[java] view plaincopyprint?
@SuppressWarnings({"rawtypes", "unchecked" })
public staticvoid main(String[] args) {
Mapmap = new TreeMap();
map.put("hello",new Date());
System.out.println(map.get("hello"));
}
@SuppressWarnings({"rawtypes", "unchecked" }) public staticvoid main(String[] args) { Mapmap = new TreeMap(); map.put("hello",new Date()); System.out.println(map.get("hello")); }
2. Deprecated:对不应再使用的方法进行注解。
[java] view plaincopyprint?
public class DeprecatedTest {
@Deprecated
public void doSomething() {
System.out.println("doSomething");
}
public static void main(String[] args) {
DeprecatedTest test = new DeprecatedTest();
test.doSomething();
}
}
public class DeprecatedTest { @Deprecated public void doSomething() { System.out.println("doSomething"); } public static void main(String[] args) { DeprecatedTest test = new DeprecatedTest(); test.doSomething(); } }
3. Override:可以保证编译时Override函数的声明正确性。只能用于方法(不能用于类,包括声明或者其他结构)
示例:
[java] view plaincopyprint?
public class OverrideTest {
@Override
public String toString(){
return "This isOverride";
}
public static void main(String[] args) {
OverrideTest test=new OverrideTest();
System.out.println(test);
}
}
public class OverrideTest { @Override public String toString(){ return "This isOverride"; } public static void main(String[] args) { OverrideTest test=new OverrideTest(); System.out.println(test); } }
三、自定义注解