Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import kotlin.test.assertEquals
- import kotlin.test.assertNotEquals
- interface Token<T: Enum<T>> {
- val type: T
- val value: String
- get() = type.name.toLowerCase()
- }
- enum class ExampleToken: Token<ExampleToken> {
- A,
- B,
- C;
- override val type = this
- }
- class ConcreteToken<T: Enum<T>>(override val type: T, override val value: String): Token<T>
- fun main(args: Array<String>) {
- val t1: Token<ExampleToken> = ExampleToken.A
- val t2: Token<ExampleToken> = ExampleToken.B
- val t3: Token<ExampleToken> = ConcreteToken(ExampleToken.A, "nope")
- val t4: Token<ExampleToken> = ConcreteToken(ExampleToken.A, "a")
- assertNotEquals(t1, t2)
- assertNotEquals(t1, t3)
- assertEquals(t1, t4, "this fails :(")
- }
Advertisement
Add Comment
Please, Sign In to add comment