A method in class Test<T>
which returns an integer....
public int getIndex(T a) //generic parameter
{
return 1; // purposely left simple
}
An array instantiated with default size 5: boolean[] arr = new boolean[5];
now I have a couple of overloading function, purposely made simple....
public void add(T a) // generic parameter
{
add(getIndex(a));
}
public void add(int a)
{
//boolean array with default size 5
arr[a] = true;
}
}
In main:
public static void main(String[] args) {
Test<Character> test = new Test<Character>();
test.add('A'); // throws exception
}
it always gives me arrayOutOfBoundException: 65
To my understaing the compiler only recognize the character as an ASCII integer value instead of invoking the method with generic type parameter, why does this happen, how do I make it work? EDIT: I made it work when I declare a Test of String type since there's no ASCII casting involved.