Skip to content

Instantly share code, notes, and snippets.

@elizarov
Created June 25, 2018 09:46
Show Gist options
  • Save elizarov/30ca944eb5390caac3362590c8472b89 to your computer and use it in GitHub Desktop.
Save elizarov/30ca944eb5390caac3362590c8472b89 to your computer and use it in GitHub Desktop.
import java.util.stream.Stream
abstract class NodeScaffold<THIS : NodeScaffold<THIS>> {
private val children: List<THIS>? = null
fun children(): Stream<THIS> {
return children!!.stream()
}
fun grandChildren(): Stream<THIS> {
return children!!.stream()
.flatMap { child -> child.children() }
}
}
abstract class SpecialNodeScaffold<THIS : SpecialNodeScaffold<THIS>> : NodeScaffold<THIS>()// special methods
abstract class VerySpecialNodeScaffold<THIS : VerySpecialNodeScaffold<THIS>> :
SpecialNodeScaffold<THIS>()// more special methods
class Node : NodeScaffold<Node>()
class SpecialNode : SpecialNodeScaffold<SpecialNode>()
class VerySpecialNode : VerySpecialNodeScaffold<VerySpecialNode>()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment