OCA Java 6, OCP Java 6, OCP Java 8
Chandella Montero wrote:How do the Strings "9" and "6" get interpreted as being an array of Strings?
OCJP6, OCWCD5
Seetharaman Venkatasamy wrote:
the second argument "6" interpreted by the compiler as new String[]{"6"} . so it matches the parameter E ... src again it is interpreted as Object[] src.
For better understanding I do suggest you to use decompiler on .class file
Do or die...?? No, Do before you die... || (SCJP .6)
deca leni wrote:Generics are a facility of allowing "a type or method to operate on objects of various types while providing compile-time type safety".
Do or die...?? No, Do before you die... || (SCJP .6)
Jeane Lindford wrote:
compiles without warnings. Doesn't the compiler check that E is used to refer to the same type at compile time?public static <E> void print(E e, E...src)
and the for loop declaration to I get a warning:public static <E, Y> void print(E e, Y...src)
OCA Java 6, OCP Java 6, OCP Java 8
Do or die...?? No, Do before you die... || (SCJP .6)
Jeane Lindford wrote:
I think I need to understand better the rules of generics types transformation... where I can find this info?
OCPJP6-05-11
"Your life is in your hands, to make of it what you choose."
--------------------
e value is type of String:false
e value is type of String arry:false
sre value is type of object array:true
|
--------------------
e value is type of String:false
e value is type of String arry:false
sre value is type of object array:true
|[I@19821f|
--------------------
e value is type of String:false
e value is type of String arry:false
sre value is type of object array:true
|9|
6|
OCA Java 6, OCP Java 6, OCP Java 8
Chandella Montero wrote:Hey Tommy, Creating Generic Methods is on page 627 in my book by the way Yeah, I re-read that part. But it doesn't mention anything about var-args or arrays being passed to var-args methods. Looking at the comments in your code, am I right to say that any array of any type passed to a var-args method is ALWAYS read as a Serializable?
--------------------
e value is type of String:false
e value is type of String arry:false
sre value is type of object array:true
OCPJP6-05-11
"Your life is in your hands, to make of it what you choose."
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|