Study on new characteristics of J2SE 1.5 tiger

Source: Internet
Author: User

First, define a simple "generic" class

package tigers;
public class GenericIdentify {
public static void main(String[] args) {
Generic1 gStr = new Generic1();
gStr.set("aaaaaaaaaaaaaaaaa");
Generic1 gInt = new Generic1();
gInt.set(new Integer(1321423));
Generic1 gBool = new Generic1();
gBool.set(new Boolean(true));
System.out.println(gStr.get() + "\n" +
gInt.get() + "\n" +
gBool.get() + "\n");
((Generic1)gInt).set("bbbbbbbbbbbbb"); //避开类型检查
System.out.println(gInt.get());
}
}
class Generic1 { //声明泛型
private A a;
public void set(A a) {
this.a = a;
}
public A get() {
return this.a;
}
}

c:\tiger>javac-d C:\tiger\cls\ C:\tiger\src\*.java

Note:c:\tiger\src\genericidentify.java uses unchecked or unsafe operations.

Note:recompile with-xlint:unchecked for details.

C:\tiger>java-classpath c:\tiger\cls Tigers. Genericidentify

Aaaaaaaaaaaaaaaaa

1321423

True

bbbbbbbbbbbbb

C:\tiger>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.