Skip to content

Instantly share code, notes, and snippets.

@falrnd
Last active February 5, 2019 10:27
Show Gist options
  • Save falrnd/fc884ba4d718f8aea48d65c9f50f607d to your computer and use it in GitHub Desktop.
Save falrnd/fc884ba4d718f8aea48d65c9f50f607d to your computer and use it in GitHub Desktop.
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