0

I'm doing an aprenticeship in an IT company as a developer.

When I ask my colleagues if the List<> item is part of the java core language, they say yes. But for me it looks like an extra feature, which is heavily used, but nonetheless an external resource. For me it's kind of confusing, because I can use the List<> in a for-each loop like: for(Object o : objectList){} So the List<> has to interact somewhere with the native for loop, so that it works.

My Questions:

*The List<> is part of the JDK, and the JDK is external, like the Standard-C-Library for C, right?

*So the Java compiler doesn't know what a List<> is and also just reads it from the JDK, like any other framework, right?

*If my assertions are right, somewhere in the List.java(or however it's called) file has to be an expression, that tells the compiler how to use it in a for-each loop?

toskana98
  • 41
  • 1
  • 3
  • Are you looking to find out [How does the Java 'for each' loop work](https://stackoverflow.com/q/85190/335858)? – Sergey Kalinichenko Jan 06 '18 at 14:10
  • @dasblinkenlight I was a bit more eager already. – Kayaman Jan 06 '18 at 14:10
  • The compiler (`javac`) doesn't know what `List` is. It has to look into `rt.jar` (for "runtime") to find the class. So no, the development kit isn't part of the core language. – Kayaman Jan 06 '18 at 14:12
  • 1
    TL;DR: `List` is not part of the Java Language. And as the answer linked by @dasblinkenlight explained, not only `List`s can be interated by an `foreach`-loop, but any datastructure, implementing the `Iterable` interface, including self-written datastructures. – Turing85 Jan 06 '18 at 14:12

0 Answers0