Tobias Bachert wrote:Type-erasure is happening, your makeArray method has compiled the type (Object[])Object[], but the generic types are still present during compile-time -> you create and pass a String array to the method (and thus receive a String array).
Your code is compiled similar to
Henry Wong wrote:
Ramsin Khoshaba wrote:
Why does ts.getClass().getComponentType() return the type before erasure in the case of varargs?
Your code is simply an example of creating an array via the reflection library (specifically, via the Array class). This method of creating arrays works, even without generics and / or varargs involved.
Henry
Henry Wong wrote:The example is this... Let's say you have code in class S, which is trying to access a protected field in superclass C (that is in a different package), and is doing it with a reference variable. Then the type of the reference variable is checked. If the type is of class S, or subclass of S, then code of class S can access protected members of C, as it is an instance that the code is responsible of the implementation.
Given a generic class declaration C<F1,...,Fn> (n > 0), the direct superclass of the parameterized class type C<T1,...,Tn>, where Ti (1 ≤ i ≤ n) is a type, is D<U1 θ,...,Uk θ>, where D<U1,...,Uk> is the direct superclass of C<F1,...,Fn> and θ is the substitution [F1:=T1,...,Fn:=Tn].
A protected member or constructor of an object may be accessed from outside the package in which it is declared only by code that is responsible for the implementation of that object.
Let C be the class in which a protected member is declared. Access is permitted only within the body of a subclass S of C.
In addition, if Id denotes an instance field or instance method, then:
If the access is by a qualified name Q.Id or a method reference expression Q :: Id (§15.13), where Q is an ExpressionName, then the access is permitted if and only if the type of the expression Q is S or a subclass of S.
Petr Omáčka wrote:
At line with comment there is no error at compile-time but at runtime there is IllegalAccesError.
What is the true reason for this behavior?
Campbell Ritchie wrote:For the purpose of your question, consider List and ArrayList the same;
Given a generic type declaration C<F1,...,Fn> (n > 0), the direct supertypes of the parameterized type C<T1,...,Tn>, where Ti (1 ≤ i ≤ n) is a type, are all of the following:
D<U1 θ,...,Uk θ>, where D<U1,...,Uk> is a generic type which is a direct supertype of the generic type C<T1,...,Tn> and θ is the substitution [F1:=T1,...,Fn:=Tn]. C<S1,...,Sn>, where Si contains Ti (1 ≤ i ≤ n) (§4.5.1). The type Object, if C<F1,...,Fn> is a generic interface type with no direct superinterfaces. The raw type C.
A type argument T1 is said to contain another type argument T2, written T2 <= T1, if the set of types denoted by T2 is provably a subset of the set of types denoted by T1 ...
Piet Souris wrote:@Ramsin
what is your background, if I may ask? Not many know about diiofantic equations. I remember doing a Project Euler problem that dealt with these things. As it turned out, I had to search Google for some theoretic results first.
Ramsin Khoshaba wrote:Now for each such permutation there should belong a 3 also. So we get,
Or, 56 such permutations.