Change the design problem through "type"?

    //
    String type = "java.lang.Integer";
    //
    String val = "100";
    //
    String var = "num";
    Demo demo = new Demo ();
    demo.setKey(var);
    demo.setType(type);
    demo.setValue(val);
    
    //
    Integer num = Integer.valueOf(profileConfig.getValue());
    System.out.println(num);
    
    type ,?
Jan.21,2022

generic design can be used. Type becomes a generic type of the Demo class, and Value is a generic type directly, so you don't have to convert it when you use it.


reflection?

Menu