Skip to content

Instantly share code, notes, and snippets.

@ledsun
Created December 9, 2011 12:30
Show Gist options
  • Select an option

  • Save ledsun/1451360 to your computer and use it in GitHub Desktop.

Select an option

Save ledsun/1451360 to your computer and use it in GitHub Desktop.
DownCastSample.java
import java.util.List;
public class DownCastSample {
public List<Integer> 警告が出る() {
Object obj = null;
List<Integer> ret = (List<Integer>) obj;
return ret;
}
public List<Integer> tryでくくっても警告が出る() {
try {
Object obj = null;
List<Integer> ret = (List<Integer>) obj;
return ret;
} catch (ClassCastException cce) {
throw cce;
}
}
public Integer[] ジェネリックでなければcastメソッドが使える() {
try {
Object obj = null;
Integer[] ret = Integer[].class.cast(obj);
return ret;
} catch (ClassCastException cce) {
throw cce;
}
}
public List<Integer> アノテーションで警告を抑制() {
Object obj = null;
@SuppressWarnings("unchecked")
List<Integer> ret = (List<Integer>) obj;
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment