Skip to content

Instantly share code, notes, and snippets.

@notyy
Created July 27, 2013 13:19
Show Gist options
  • Save notyy/6094844 to your computer and use it in GitHub Desktop.
Save notyy/6094844 to your computer and use it in GitHub Desktop.
implicit abstract class problem
package base;
import java.util.List;
public abstract class AbstractBase {
abstract protected List getChildren();
}
package base
import java.util
object BaseImplit {
implicit class SBase[T <: AbstractBase](child: T) extends AbstractBase {
protected def getChildren: util.List[_] = child.getChildren
def apply = child.getChildren
}
}
package com.github.notyy.retroboard.util
import base.AbstractBase
import scala.collection.JavaConverters._
class Child1 extends AbstractBase {
protected def getChildren: java.util.List[String] = List("child1").asJava
}
class Child2 extends AbstractBase {
def getChildren: java.util.List[String] = List("child2").asJava
}
object ImplicitTest extends App{
import base.BaseImplit._
println(new Child1().apply)
println(new Child2().apply)
}
@notyy
Copy link
Author

notyy commented Jul 27, 2013

output is

[child1]
[child2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment