So, I just started learning Scala today, and have been doing fairly well, but I’ve run into a wall, with this problem…
I need to do this in Scala, but am having trouble sorting it out:
final Filter<GameObject> filter = new Filter<GameObject>() {
public boolean accept(GameObject o) {
...
}
};
ATM I have, but it won’t even compile:
val filter = new Filter[GameObject] {
override def accept(o: GameObject) {
...
}
}
Thanks in advance.
Edit:
Here is the entire object so far:
object Targeter extends LoopTask {
val filter = new Filter[GameObject] {
override def accept(o: GameObject) = { true }
}
// Overriding a method in the LoopTask class
override def loop() = {
100
}
}
I think you missed return type:
or
These two variants are the same (assuming that you actually return some boolean in the body of this method).
If you define
acceptmethod like this:then it’s the same as:
And
Unitis equivalent ofvoidin java.