public Class converstion(String chaine, Class clazz) throws ClassNotFoundException { Class rtn = null; Class test = instanciation("reflect.UserBeanIn", "getPrenom"); if (test.getClass().equals(clazz)) { try { System.out.println("true" + Integer.parseInt(chaine)); } catch (Exception e) { System.out.println("false"); } } return rtn; }
converstion("12", Integer.class);
public class PasCompris extends JFrame { private JPanel contentPane; private JTextField textField; String getTextField() { String text = textField.getText(); return text; } int getTextFieldAsInt() throws NumberFormatException { String text = textField.getText(); return Integer.parseInt(text); } // etc. }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpublic Class conver(<String>, <Class variable>)
public Class conver(<String>, <type primtif variable>)
public Class converstion(String chaine, Class clazz) throws ClassNotFoundException { Class rtn = null; Class test = instanciation("reflect.UserBeanIn", "getPrenom"); // A changer ? if (test.equals(clazz)) { try { if (clazz.getClass().getName().equals("java.lang.Integer")) System.out.println("true" + Integer.parseInt(chaine)); else if (clazz.getClass().getName().equals("java.lang.Long")) System.out.println("true" + Long.parseLong(chaine)); // etc. else System.out.println("false"); } catch (Exception e) { System.out.println("false"); } } return rtn; } void convertions() { try { converstion("12", Integer.class); converstion("12", Long.class); } catch (ClassNotFoundException e) { } }