Sergej Chodarev
Sergej Chodarev
function foo(data) {
...
return bar(data);
}
(define (factorial n)
(if (= n 1)
1
(* n (factorial (- n 1)))))
(define (factorial n)
(define (iter product counter)
(if (> counter n)
product
(iter (* counter product)
(+ counter 1))))
(iter 1 1))
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Main.sayHello(Main.java:8)
at Main.main(Main.java:4)
Throwable
void printStackTrace()
StackTraceElement[] getStackTrace()
String getFileName()
int getLineNumber()
String getClassName()
String getMethodName()
boolean isNativeMethod()
public interface Logger {
void logRecord(String className,
String methodName,
int lineNum,
String message,
int logRecordType);
...
}
public interface Logger {
void logRecord(String message,
int logRecordType);
...
}
public void logRecord(String message, int logRecordType) {
Throwable ex = new Throwable();
StackTraceElement ste = ex.getStackTrace()[1];
String callerClassName = ste.getClassName();
String callerMethodName = ste.getMethodName();
int callerLineNum = ste.getLineNumber();
...
StackWalker walker = StackWalker.getInstance(
Option.RETAIN_CLASS_REFERENCE);
Optional<Class<?>> callerClass = walker.walk(s ->
s.map(StackFrame::getDeclaringClass)
.filter(interestingClasses::contains)
.findFirst());
int x = 5;
int y = 10;
int z = x + y * 7;
0: iconst_5
1: istore_1
2: bipush 10
4: istore_2
5: iload_1
6: iload_2
7: bipush 7
9: imul
10: iadd
11: istore_3
Class<?> Class.forName(String className)
ClassName.class
?
String dbClassName = props.getProperty("dbClass", "sk.tuke.StubDB");
Class dbClass = Class.forName(dbClassName);
customerDB = (CustomerDatabase) dbClass.newInstance();
Class cls = Class.forName(name);
ClassLoader loader = this.getClass().getClassLoader();
Class cls = Class.forName(name, true, loader);
Class cls = loader.loadClass(name);
this.getClass().getClassLoader();
ClassLoader.getSystemClassLoader();
Thread.currentThread().getContextClassLoader();
new URLClassLoader(urls);
ClassLoader
java.lang.reflect.Proxy
Class c = getProxyClass(SomeInterface.class.getClassLoader(), SomeInterface.class);
Constructor cons = c.getConstructor(InvocationHandler.class);
Object proxy = cons.newInstance(new SomeIH(obj));
Object proxy = Proxy.newProxyInstance(
SomeInterface.class.getClassLoader(),
new Class[]{ SomeInterface.class },
new SomeIH(obj));
Object invoke(Object proxy, Method method, Object[] args)
Object
:
hashCode
, equals
, toString
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
return method.invoke(target, args);
}