thana
02/14/2019, 1:10 PMLeoColman
02/14/2019, 3:33 PMEnum.hashCode()
?elect
02/14/2019, 5:44 PMIntBuffer
in the corresponding companion object?elect
02/14/2019, 5:45 PMenum class Buffer { VERTEX, ELEMENT; companion object { val names: IntBuffer } }
inline fun <E> Enum<E>.bind(..) {
// do something on names
}
elect
02/14/2019, 5:49 PMbjonnh
02/25/2019, 11:20 PMbjonnh
02/25/2019, 11:20 PMbjonnh
02/25/2019, 11:20 PMnkiesel
02/26/2019, 2:08 AMval formatter = DateTimeFormatterBuilder()
.appendPattern("yyyy-MM-dd'T'HH:mm:ss")
.appendFraction(ChronoField.MILLI_OF_SECOND, 1, 3, true) // min 1, max 3 digits
.toFormatter()
val formatDateTime = LocalDateTime.parse(value, formatter)
natpryce
02/26/2019, 9:14 AMfun <B> test(): B where A: B
natpryce
02/26/2019, 9:16 AMwhere
clause than you can in the parameter declaration itselfJeremy
02/26/2019, 9:17 AMA does not refere to a type paramter of test
natpryce
02/26/2019, 9:22 AMout
variance from <A>natpryce
02/26/2019, 9:22 AMnatpryce
02/26/2019, 9:22 AMJeremy
02/26/2019, 9:24 AMfun <B, A : B> test(): B
natpryce
02/26/2019, 9:24 AMnatpryce
02/26/2019, 9:29 AMA
in A: B
is coloured as an unused declaration. And if you rename it, the type parameter on the class is not also renamed.natpryce
02/26/2019, 9:29 AMfun <B> test(): B
, but you’ll probably get type inference errors at call points.Jeremy
02/26/2019, 9:30 AMfun <B, A : B> test(): B
is still correct answer, right?natpryce
02/26/2019, 9:31 AMnatpryce
02/26/2019, 9:31 AMRobert Jaros
02/26/2019, 9:31 AMnatpryce
02/26/2019, 9:33 AMin
variance constraint on those type parameters. Not sure why.natpryce
02/26/2019, 9:33 AMnatpryce
02/26/2019, 9:34 AMtest
function that tells the implementation of the function how to decide what B should be. So the type inference has nothing to work on.natpryce
02/26/2019, 9:36 AMtest
will return a supertype of A, but I don’t know which. Or is it meant to specify: test
will return an A, but you can treat it as a supertype of A if you wish.natpryce
02/26/2019, 9:36 AMJeremy
02/26/2019, 10:58 AM[B >: A]
which means the type B is supertype of A. How can I implement this code to kotlin?
sealed abstract class Option[+A] extends Product with Serializable {
self =>
...
@inline final def getOrElse[B >: A](default: => B): B =
if (isEmpty) default else this.get
...
natpryce
02/26/2019, 11:00 AMdefault
thunk you pass in lets the compiler bind the type of B. In the example above, test
does not have an argument that lets the compiler know anything about B