Using generics for problem solving under eclipse

Source: Internet
Author: User

Generics in Java appear in later versions of J2SE5, development platform: eclipse3.2+ jdk1.6 encountered an error with an IDE tool at one time using the Java generics, and then looked for the reason: eclipse3.2 the default compilation is to use 1.4 to create generics that do not use Java.

WORKAROUND: Window-->perfernces-->java-->compiler-->compiler compliance lever in Eclipse's menu

Change 1.4 to 5.0 or 6.0 (set according to JDK version).

Example:

1package fanxing;
2
3import java.util.Hashtable;
4
5public class Good<k,v> {
6
7/** *//**
8 * @param args
9 */
Ten public hashtable<k,v> h=new hashtable<k,v> ();
One public void put (k K, v V) {
H.put (K,V);
13}
Public V get (k k) {
Return H.get (k);
16}
17
public static void Main (string[] args) {
//TODO auto-generated method stub
good<string, string> TG = new good<string, string> ();
Tg.put ("Key", "value");
System.out.println (Tg.get ("key"));
23
24
25}
26
27}
28

Output: Value

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.