1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
interface A <E>
{
public E getVal () ;
public void setVal(E e);
}
class W <String> implements A
{
Object w ;
W () {//fonction speciale de creation de String}
public Object getVal() {
return w;
}
public void setVal(Object e) {
w = e ;
}
}
class X <Integer> implements A
{
Integer x ;
X () {//fonction speciale de creation de Integer}
public Integer getVal() {
return x;
}
public void setVal(Object e) {
x = (Integer)e ;
}
}
public class TestMain
{
public static void main(String[] args)
{
A<?> w = new W<String> () ;
w.setVal("string") ;
kesako(w.getVal()) ;
A x = new X () ;
x.setVal(2);
kesako(x.getVal()) ;
}
static void kesako (String s)
{
System.out.println("STRING");
}
static void kesako (Integer s)
{
System.out.println("INTEGER");
}
} |
Partager