package jtests;
import java.lang.System;
public class MyTest {
class A {
String a () {
return("from A:a");
}
String b() {
return("from A:b - " + a());
}
}
class B extends A {
@Override String b() {
return ("from B:b - " + super.b());
}
}
public static void main(String[] args) {
MyTest m = new MyTest();
System.out.println("A");
A a = m.new A(); // Используем A
System.out.println(a.getClass().getName() + " * " + a.b());
System.out.println("B");
B b = m.new B(); // Используем B
System.out.println(b.getClass().getName() + " * " + b.b());
System.out.println("B -> A");
A ab = (A) m.new B(); // Используем B как A
System.out.println(ab.getClass().getName() + " * " + ab.b());
}
}
A
jtests.MyTest$A * from A:b - from A:a
B
jtests.MyTest$B * from B:b - from A:b - from A:a
B -> A
jtests.MyTest$B * from B:b - from A:b - from A:a
package my.com;
import java.util.HashMap;
import java.util.Map;
public class MyJob {
class Context {
private String astring;
public Context(String string){
this.setAstring(string);
// set properties
}
public String getAstring() {
return astring;
}
public void setAstring(String astring) {
this.astring = astring;
}
}
interface Worker {
public int doWork(Context c);
}
class MultiChoose implements Worker {
@Override
public int doWork(Context c) {
c.getAstring();
System.out.println(c.getAstring() +" MultiChoose");
c.setAstring("Новая фигня");
return 0;
}
}
class Choose implements Worker {
@Override
public int doWork(Context c) {
System.out.println(c.getAstring() +" Choose");
return 0;
}
}
class AnotherString implements Worker {
@Override
public int doWork(Context c) {
System.out.println(c.getAstring() + " AnotherString");
return 0;
}
}
class Nothing implements Worker {
@Override
public int doWork(Context c) {
System.out.println("Nothing");
return 1;
}
}
public static void main(String[] args) {
MyJob job = new MyJob();
Map<String, Worker> cases = new HashMap<String, Worker>();
cases.put("Выбор", job.new Choose());
cases.put("МультиВыбор", job.new MultiChoose());
cases.put("yetanotherSubString", job.new AnotherString());
String[] keys_for_test = {"Выбор","МультиВыбор","yetanotherSubString","WrongKey"};
Context content = job.new Context("Всякая фигня");
for (String key:keys_for_test) {
Worker worker = cases.getOrDefault(key, job.new Nothing());
worker.doWork(content);
}
}
}
Всякая фигня Choose
Всякая фигня MultiChoose
Новая фигня AnotherString
Nothing
BSFManager manager = new BSFManager();
Vector<String> ignoreParamNames = null;
Vector<Integer> args = new Vector<Integer>();
args.add(2);
args.add(5);
args.add(1);
Integer actual = (Integer) manager.apply("groovy", "applyTest", 0, 0,
"def summer = { a, b, c -> a * 100 + b * 10 + c }", ignoreParamNames, args);
assertEquals(251, actual.intValue());