i am running some tests to better understand java generic methods, and came across the following problem. i have the following simple class:
1 public class SomeClass<O extends Object> {
2
3 O someVar;
4
5 public SomeClass() {
6 someFunc(new Number(1));
7 }
8
9 public void someFunc(O arg) {
10 // code
11 }
12 }
as it stands, the compiler does not like line 6. eclipse suggests to either cast Number instance to O, or change argument type to Number on line 9. i would really like to avoid both if possible. i know that modifying the class like so takes care of this problem:
1 public class SomeClass {
2
3 O someVar;
4
5 public SomeClass() {
6 someFunc(new Number(1));
7 }
8
9 public <O extends Object> void someFunc(O arg) {
10 // code
11 }
12 }
but that brings a new problem with line 3.
so what can be done with my original code?
thank you for your time!!!