Position:Home>JAVA Development> Java extensive understanding and equal in value implementation
Java extensive understanding and equal in value implementation
From;  Author:Stand originally

IntOb.showTyep();
Int I= IntOb.getOb();
System.out.println("value= " I);

System.out.println("----------------------------------") ;

/ / definition extensive kind the version of a String of Gen
Gen<String>StrOb=new Gen<String>("Hello Gen! ") ;
StrOb.showTyep();
String S=strOb.getOb();
System.out.println("value= " S);
}
}

Example 2: Did not use extensive model
Public Class Gen2 {
Private Object Ob; // defines member of a general kind

Public Gen2(Object Ob) {
This.ob = Ob;
}

Public Object GetOb() {
Return Ob;
}

Public Void SetOb(Object Ob) {
This.ob = Ob;
}

Public Void ShowTyep() {
The real kind of System.out.println("T is: " Ob.getClass().getName());
}
}
Public Class GenDemo2 {
Public Static Void Main(String[] Args) {
/ / an Integer version that defines kind of Gen2
Gen2 IntOb = New Gen2(new Integer(88));
IntOb.showTyep();
Int I = (Integer) IntOb.getOb();
System.out.println("value= " I);

System.out.println("----------------------------------") ;

/ / the version of a String that defines kind of Gen2
Gen2 StrOb = New Gen2("Hello Gen! ") ;
StrOb.showTyep();
String S = (String) StrOb.getOb();
System.out.println("value= " S);
}
}

Moving result:

Result of two example moving Demo is identical, console output is as follows as a result:

The real kind of T is:
Java.lang.IntegerValue= 88
----------------------------------
The real kind of T is: Java.lang.StringValue= Hello Gen!

Process Finished With Exit Code 0

Look understand this, basic extensive application is mixed after code is read unchallenged.

Previous 1 2Next
Previous:The abstraction in detailed and analytic Java kind the distinction with interfac
Next:JAVA tutorial: The multi-line Cheng mechanism of analytic Java