Created
May 9, 2014 18:30
-
-
Save admiyo/96fb433f59fa9b54ab32 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package com.younglogic.dictionary; | |
| import java.util.Dictionary; | |
| import java.lang.reflect.Constructor; | |
| import java.lang.reflect.Executable; | |
| import java.lang.reflect.Parameter; | |
| public class User { | |
| public final int uid; | |
| public final int gid; | |
| public final String loginShell; | |
| public final String jobTitle; | |
| public final String name; | |
| public User(int uid, int gid, String loginShell, String jobTitle, | |
| String name) { | |
| super(); | |
| this.uid = uid; | |
| this.gid = gid; | |
| this.loginShell = loginShell; | |
| this.jobTitle = jobTitle; | |
| this.name = name; | |
| } | |
| public String toString(){ | |
| return String.format("uid %d, gid %d, loginShell %s, jobTitle %s, name %s", | |
| this.uid, this.gid, this.loginShell, this.jobTitle, this.name); | |
| } | |
| public static User factory(Dictionary<String, String> props){ | |
| return new User(Integer.parseInt(props.get("uid")), | |
| Integer.parseInt(props.get("gid")), | |
| props.get("loginShell"), | |
| props.get("jobTitle"), | |
| props.get("name")); | |
| } | |
| public static void main(String[] args){ | |
| User user = new User(1,2,"/bin/bash", "codemonkey", "Adam"); | |
| Class c = User.class; | |
| Constructor constructor = c.getConstructors()[0]; | |
| for (Parameter param: constructor.getParameters()){ | |
| System.out.println (param.getName()); | |
| } | |
| return; | |
| } | |
| } | |
| produces: | |
| $ ./compile.sh | |
| + JAVAC=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.0.x86_64/bin/javac | |
| + JAVA=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.0.x86_64/bin/java | |
| + /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.0.x86_64/bin/javac src/com/younglogic/dictionary/User.java | |
| + /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.0.x86_64/bin/java -cp src com.younglogic.dictionary.User | |
| arg0 | |
| arg1 | |
| arg2 | |
| arg3 | |
| arg4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment