Created
October 28, 2011 01:43
-
-
Save kunitoo/1321429 to your computer and use it in GitHub Desktop.
古今東西java.langの判定プログラムを愚直に作ってみた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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