0

I have following code:

List<Integer> ints = Arrays.asList(1,2,3,4);

asList, defined in java.util.Arrays is as:

public static <T> List<T> asList(T... a) {
    return new ArrayList<>(a);
}

And AaaryList constructor is defined as:

ArrayList(E[] array) {
    a = Objects.requireNonNull(array);
}

I was expecting to find some code for autoboxing,and some code which determines type of the elements passed to asList method as we can pass any type to asList, but no such code is there.

So how does all this type detection, autoboxing etc occurs in this entire scheme of things.

Mandroid
  • 6,200
  • 12
  • 64
  • 134
  • 2
    Autoboxing and type inference happens automatically, so you don't need extra code to _do_ them. Does that answer your question? – Sweeper May 23 '20 at 17:11
  • 2
    Type parameter resolution is performed during compilation, not runtime, there will be no code for this – Vasily Liaskovsky May 23 '20 at 17:11
  • ok, so you mean compilation process executes some code of its own to do the necessary things. And where can I have a look at this code? – Mandroid May 23 '20 at 17:13
  • [This post](https://stackoverflow.com/questions/1584544/where-is-the-source-code-for-the-java-compiler) tells you where the source code for the Java Compiler is. Another (possibly more useful resource if you want to learn about how the language works) is the [JLS](https://docs.oracle.com/javase/specs/jls/se8/html/jls-18.html). – Sweeper May 23 '20 at 17:23
  • Well, there are some specifications about Java language, but actual implementation may vary. Check for example https://docs.oracle.com/javase/specs/jls/se8/html/index.html, chapters 4.5 - 4.8 – Vasily Liaskovsky May 23 '20 at 17:23

0 Answers0