RSS
热门关键字:
当前位置 :| 主页>JAVA Development>

Java extensive understanding and equal in value implementation

来源: 作者:Stand originally 时间:2008-12-21 Tag: 点击:

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.

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
栏目列表
热点关注
相关文章