Created
July 27, 2013 13:19
-
-
Save notyy/6094844 to your computer and use it in GitHub Desktop.
implicit abstract class problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package base; | |
import java.util.List; | |
public abstract class AbstractBase { | |
abstract protected List getChildren(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output is
[child1]
[child2]