I am having trouble with using Java capture groups correctly.
Suppose I have these classes:
class Foo{}
class Bar{}
interface InterfaceXYZ<T>{
void doSomething(T t);
}
class FooImplementation implements InterfaceXYZ<Foo>{
@Override void doSomething(Foo){}
}
Finally,
class Delegator<T>{
Delegator(InterfaceXYZ<T> delegate){this.delegate = delegate;}
void doSomething(T t) {
delegate.doSomething(t);
}
private InterfaceXYZ<T> delegate;
}
The problem is this works fine -
FooImplementation fi = new FooImplementation();
Delegator d = new Delegator(fi);
d.doSomething(new Foo());
This does not work fine (as expected) - causes a runtime exception
FooImplementation fi = new FooImplementation();
Delegator d = new Delegator(fi);
d.doSomething(new Bar());
Why doesn't it throw a compile time error? If I have to make it throw a compile time error, what changes do I need to make?