Is there an auto
variable type in Java like you have in C++?
An example:
for ( auto var : object_array)
std::cout << var <<
In Java 8, you can use lambda type inference to avoid declaring the type. The analogue to the questioner's examples would be:
object_array.forEach(obj -> System.out.println(obj));
object_array.forEach(obj -> obj.do_something_that_only_this_particular_obj_can_do());
both of which can also be simplified using method references:
object_array.forEach(System.out::println);
object_array.forEach(ObjectType::do_something_that_only_this_particular_obj_can_do);