Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Java Object Info
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; import java.lang.reflect.*; class Rextester { public static final String NL = System.lineSeparator(); public static void main(String args[]) throws Exception { StringBuilder sb = new StringBuilder(); Class<?> c = Class.forName(new Scanner(System.in).nextLine()); String name = c.getName(); sb.append("**"); for(int i = 0; i < name.length(); i++) sb.append("*"); String sep = sb.append("**").append(NL).toString(); sb.append("* ").append(name).append(" *") .append(NL).append(sep); sb.append("* Superclasses:").append(NL); for(Class<?> cl = c.getSuperclass(); cl != null; cl = cl.getSuperclass()) sb.append("* ").append(cl.getName()).append(NL); sb.append(sep).append("* Fields:").append(NL); for(Class<?> cl = c; cl != Object.class; cl = cl.getSuperclass()) for(Field f : cl.getDeclaredFields()) { String mod = Modifier.toString(f.getModifiers()); if(mod.isEmpty()) mod = "package private"; sb.append("* ").append(mod).append(" ").append(f.getType().getSimpleName()).append(" ").append(f.getName()).append(NL); } sb.append(sep).append("* Methods:").append(NL); for(Class<?> cl = c; cl != null; cl = cl.getSuperclass()){ for(Method m : cl.getDeclaredMethods()){ StringJoiner sjs = new StringJoiner(" "); String mod = Modifier.toString(m.getModifiers()); if(mod.isEmpty()) mod = "package private"; sjs.add("*").add(mod).add(m.getReturnType().getSimpleName()).add(m.getName()); sb.append(sjs.toString()); StringJoiner sj = new StringJoiner(", ", "(", ")"); for(Class<?> par : m.getParameterTypes()){ sj.add(par.getSimpleName()); } sb.append(sj.toString()).append(NL); } } System.out.println(sb); } }
run
|
edit
|
history
|
help
0
Program to generate random no. From 0 to 10
piglatin
jb15.0
3f
4.C
Coding Challenge - 03 (Prime numbers)
dfkbzhfvjahfjh
Java
OBF-7 4
String