ubu
08/23/2018, 12:11 PMclass A(val someObject : SomeObjectClass) {
fun doSomethingWithSomeObject() {
// TODO do something with someObject
}
}
How would I achieve something like the following in Kotlin:
coolDSL(someObject) {
doSomethingWithSomeObject {
someObject.callSomeMethod()
}
}
Thanks in advance.temp_man
08/23/2018, 4:03 PMtschuchort
08/23/2018, 8:46 PMbdawg.io
08/23/2018, 8:55 PMpublic static final void main(@NotNull String[] args) {
Intrinsics.checkParameterIsNotNull(args, "args");
MyType bar$iv = new MyType();
doSomething(bar$iv);
}
karelpeeters
08/23/2018, 11:19 PMjurajsolarml
08/24/2018, 11:15 AMsksk
08/24/2018, 12:01 PMhttps://i.imgur.com/icK7bBl.png▾
supaham
08/25/2018, 5:15 PMchickenfresh
08/25/2018, 5:29 PMlifter
08/25/2018, 7:04 PMprintln(f())
prints “Yes” instead of “No”?
fun main(args: Array<String>) {
var (f, x) = g()
println(f()) // Prints "yes"
x = 1
println(f()) // Prints "yes"
}
fun g(): Pair<() -> Char, Int> {
var x = 0
var f = fun(): Char { return if (x == 0) { println("yes"); 'Y' } else { println("no"); 'N' } }
return f to x
}
chickenfresh
08/25/2018, 7:15 PMval curSelectedItem = SimpleObjectProperty<ItemViewInstance>()
with something like this
when (curSelectedItem) { is ItemViewInstance.ItemModel }
?
it works only if curSelectedItem
isnt SimpleObjectProperty
Felix
08/26/2018, 8:49 PMjanvladimirmostert
08/27/2018, 6:30 AMmvn clean package
to run in 20-24 minutes
even with the incremental option on, that first mvn package
or running it from IntelliJ takes almost 30 minutes
not sure if Kotlin compile times became much slower or if our code-base became exponentially bigger
we have about 2k lines of Java code and 114k lines of Kotlin code, so not that enormous
any suggestions on how to make it faster?
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<configuration>
<jvmTarget>${java.version}</jvmTarget>
<compilerPlugins>
<plugin>jpa</plugin>
</compilerPlugins>
<pluginOptions>
<option>jpa:annotation=javax.persistence.MappedSuperclass</option>
</pluginOptions>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/main/java</source>
<source>src/main/kotlin</source>
<source>src/main/resources</source>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>process-test-sources</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/test/java</source>
<source>src/test/kotlin</source>
<source>src/test/resources</source>
</sourceDirs>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
jacob
08/27/2018, 8:01 AMcoder82
08/27/2018, 9:37 AMJakub
08/27/2018, 1:35 PMfun read(bufferedReader: BufferedReader): List<String>
because when mocking File
, file.bufferedReader
gives NullPointerException
Jakub
08/27/2018, 3:29 PMBernhard
08/27/2018, 3:39 PMcoder82
08/27/2018, 4:28 PMpasssy
08/27/2018, 7:19 PMMutableList<T>
with a delegate. The class doesn’t have other properties. How can I write a working equals
method which includes the delegate. Can I access it somehow?
class WidgetListBuilder : MutableList<Widget> by mutableListOf() {
inline fun <T : Widget> add(widget: T, init: T.() -> Unit): T {
widget.apply(init)
add(widget)
return widget
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is WidgetListBuilder) return false
// TODO handle list
return true
}
override fun hashCode(): Int {
return javaClass.hashCode()
}
}
pavel
08/27/2018, 10:40 PMopen class Outer {
val inner = Inner()
open val foo = 3
open inner class Inner {
val innerFoo = foo // Accessing non-final property foo in constructor
}
}
?groostav
08/27/2018, 10:42 PMkarelpeeters
08/28/2018, 5:55 AMfold
for things like that.no
08/28/2018, 8:24 AMjakub.dyszkiewicz
08/28/2018, 9:29 AMString#toString
implementation?
I can see in Java
public String toString() {
return this;
}
but I can’t see this in Kotlin.
public class String : Comparable<String>, CharSequence {
companion object {}
/**
* Returns a string obtained by concatenating this string with the string representation of the given [other] object.
*/
public operator fun plus(other: Any?): String
public override val length: Int
public override fun get(index: Int): Char
public override fun subSequence(startIndex: Int, endIndex: Int): CharSequence
public override fun compareTo(other: String): Int
}
I can’t find extension function either…Dominaezzz
08/28/2018, 7:19 PMshr
, shl
, and
and or
instead of >>
, <<
, &
and |
?lifter
08/28/2018, 8:12 PMNothing
in this case...
fun justThrowIt(): Nothing = throw IOException()
...while here, I'm not:
fun justLoop() { while (true) {} }
lifter
08/28/2018, 8:14 PMfun justLoop(): Nothing { while (true) {} }
, the code does compile.wei
08/29/2018, 2:37 AMA
that has an abstract member property defined by an interface:
interface Tool {
fun run(command: String): Boolean
}
abstract class A {
abstract protected var tool: Tool
fun execute(command: String) : Boolean {
return tool.run(command)
}
}
Then I have another class B
that inherits from A
and uses guice to inject the tool
member property at startup.
class B {
@Inject
@Transient
override protected var tool: Knife
}
where Knife
is a concrete class implementing the interface Tool
.
Intellij is complaining to me:
Var property tye is `Knife`, which is not a type of overridden protected abstract var tool: Tool defined in com.myorg....
.adam-mcneilly
08/29/2018, 1:22 PMassertFalse
function in Kotlin test requires a non null boolean. What is the most idiomatic way to handle a nullable boolean?
assertFalse(condition ?: true)
is one. We could also invert it and say assertTrue(condition == false)
but honestly I wish I could just pass a nullable boolean. I'm not sure why we couldn't.adam-mcneilly
08/29/2018, 1:22 PMassertFalse
function in Kotlin test requires a non null boolean. What is the most idiomatic way to handle a nullable boolean?
assertFalse(condition ?: true)
is one. We could also invert it and say assertTrue(condition == false)
but honestly I wish I could just pass a nullable boolean. I'm not sure why we couldn't.spand
08/29/2018, 1:26 PMassertThat(condition, equalTo(false))
gildor
08/29/2018, 5:49 PM