課題
ちょっと難しくなったかな。
プリミティブ型を使うとは……
public class Test { public static void main(String[] args) throws Exception { kata(new Double(10.0)); kata(new Integer(10)); kata("10"); kata(new Long(10)); } public static void kata(Object args) throws Exception { try { Integer intResult = (Integer) args; System.out.println("Integer型"); } catch (Exception inte) { try { Double dblResult = (Double) args; System.out.println("Double型"); } catch (Exception dble) { try { String strResult = (String) args; System.out.println("String型"); } catch (Exception stre) { System.out.println("そのほかの型"); System.out.println(stre); } } } } }