Skip to content

Instantly share code, notes, and snippets.

@kunitoo
Created October 28, 2011 01:43
Show Gist options
  • Save kunitoo/1321429 to your computer and use it in GitHub Desktop.
Save kunitoo/1321429 to your computer and use it in GitHub Desktop.
古今東西java.langの判定プログラムを愚直に作ってみた
package game;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class KokonTouzai {
public static void main(String[] args) throws IOException{
KokonTouzai kokonTouzai = KokonTouzai.newInstance();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String name = null;
while (!"exit".equals(name)) {
System.out.print("input ClassName-> ");
name = reader.readLine();
System.out.println("result:" + kokonTouzai.hasName(name));
}
}
private String packageName;
private KokonTouzai() { }
public static KokonTouzai newInstance() {
KokonTouzai result = new KokonTouzai();
result.packageName = "java.lang";
return result;
}
public Boolean hasName(String className) {
String name = packageName + "." + className;
try {
Class.forName(name);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment