Last active
February 5, 2019 10:27
-
-
Save falrnd/fc884ba4d718f8aea48d65c9f50f607d to your computer and use it in GitHub Desktop.
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
import java.lang.reflect.*; | |
import java.util.*; | |
class Main{ | |
public static void main(String[] $) throws Exception{ | |
Scanner s=new Scanner(System.in); | |
Field[] fields=Main.class.getDeclaredFields(); | |
for(int i=0;i<fields.length;++i){ | |
Field field=fields[i]; | |
autofill(s,field,field.getType().getSimpleName()); | |
} | |
new Main().solve(s); | |
} | |
private static void autofill(Scanner s,Field field,String typename) throws IllegalAccessException{ | |
switch(typename){ | |
case "int": | |
field.setInt(null,Integer.parseInt(s.next())); | |
break; | |
case "long": | |
field.setLong(null,Long.parseLong(s.next())); | |
break; | |
case "double": | |
field.setDouble(null,Double.parseDouble(s.next())); | |
break; | |
case "char": | |
field.setChar(null,s.next().charAt(0)); | |
break; | |
case "char[]": | |
field.set(null,s.next().toCharArray()); | |
break; | |
case "String": | |
field.set(null,s.next()); | |
break; | |
default: | |
if(typename.endsWith("[]")){ | |
throw new UnsupportedOperationException("todo"); | |
}else{ | |
throw new IllegalArgumentException("undefined autofill"); | |
} | |
} | |
} | |
void solve(Scanner s){ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment