Skip to content

Instantly share code, notes, and snippets.

@hagun
Created November 19, 2015 02:32
Show Gist options
  • Select an option

  • Save hagun/47d377579d071acb4cde to your computer and use it in GitHub Desktop.

Select an option

Save hagun/47d377579d071acb4cde to your computer and use it in GitHub Desktop.
삼항연산자
public class Db {
public static void main(String[] args) {
Object a = (true ? new Integer(1) : new Double(1.0));
System.out.println(a);
if (a instanceof Integer) {
System.out.println("Integer");
} else if (a instanceof Double) {
System.out.println("Double");
}
}
}
public class Str {
public static void main(String[] args) {
Object a = (true ? new Integer(1) : new String("test"));
System.out.println(a);
if (a instanceof Integer) {
System.out.println("Integer");
} else if (a instanceof String) {
System.out.println("String");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment