Skip to content

Instantly share code, notes, and snippets.

@RuZman
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RuZman/a92b18e0502191906ebd to your computer and use it in GitHub Desktop.
Save RuZman/a92b18e0502191906ebd to your computer and use it in GitHub Desktop.
import java.util.Objects;
public class SubClass2 extends AClass {
public static void main(String[] args) {
System.out.println(new SubClass2(6).getValue1());
}
public SubClass2(int value) {
super(new MyCalculation(value));
}
private static class MyCalculation implements ICalc {
private int value;
public MyCalculation(int value) {
this.value = value;
}
@Override
public int getValue() {
return value + 10;
}
}
}
abstract class AClass {
private final int value1;
public AClass(ICalc calc) {
this.value1 = Objects.requireNonNull(calc.getValue());
}
public final int getValue1() {
return value1;
}
}
interface ICalc {
int getValue();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment