Adrian M
04/11/2018, 12:55 PM@BeforeAll
annotated method from super class be executed before tests from child class?
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
open class TestBase {
var status: Boolean = false
@BeforeAll
open fun setStatus() {
status = true
}
}
class MyAppTest : TestBase() {
@test
fun testStatus() {
assertTrue(status) //fails
}
}
Nelson Plinio
04/11/2018, 12:56 PMAndreas Sinz
04/11/2018, 2:20 PMJoel Armstrong
04/11/2018, 5:35 PMpublic class PublicClassProtectedConstructor {
protected PublicClassProtectedConstructor(params...)
}
public class Factory {
public static PublicClassProtectedConstructor factoryMethod1(...) ...
public static PublicClassProtectedConstructor factoryMethod2(...) ...
}
Joel Armstrong
04/11/2018, 5:39 PMjasondlee
04/11/2018, 7:52 PMjasondlee
04/12/2018, 2:51 AMAndrzej Sawoniewicz
04/12/2018, 9:52 AMYuku Kotani
04/12/2018, 10:45 AM@kotlin.internal.InlineOnly
public inline fun <reified K: Any, V> mapOf(): Map<K, V> =
if (K::class.java.isEnum) EnumMap<K, V>(K::class.java)
else emptyMap()
Type argument is not within its bounds.
Expected: Enum<K!>!
Found: K
Jitesh Dedhiya
04/12/2018, 10:51 AMShawn
04/12/2018, 3:13 PMmbickel
04/12/2018, 3:33 PMRuckus
04/12/2018, 8:07 PMval add: (Int, Int) -> Int = { a, b -> a + b }
val add5: (Int) -> Int = { add(it, 5) }
assert(add5(10) == 15)
MattIPv4
04/13/2018, 9:46 AMrmarinsky
04/13/2018, 10:35 AMdierre
04/13/2018, 2:18 PMclass Car (
val model: String?,
val year: Int,
val required: String
) {
private constructor(builder: Builder) : this(builder.model, builder.year, builder.required)
companion object {
inline fun build(required: String, block: Builder.() -> Unit) = Builder(required).apply(block).build()
}
class Builder(
val required: String
) {
var model: String? = null
var year: Int = 0
fun build() = Car(this)
}
}
so that in kotlin I can do val car = Car.build(required = "") {
model = "X"
year = 120
}
The problem is that in Java then I need to write: Car.Builder builder = new Car.Builder("required");
builder.setModel("X");
builder.build();
to do the same stuff. This is not really readable. So I did something this: class CarJavaFriendly(private val model: String?, private val year: Int) {
private lateinit var required: String
fun withRequired(b: String) = this.apply { required = b }
fun execute() {
tryExecute { someFunction() } }
}
private fun <B> tryExecute(f: () -> B): B = try {
f()
} catch (e: UninitializedPropertyAccessException) {
val msg = e.message?.replace("lateinit property ", "") ?: "a property has not been initialized"
throw ValueRequiredException(msg)
}
}
so that in java you can write CarJavaFriendly carJavaFriendly =
new CarJavaFriendly("X", 1)
.withRequired("x")
.execute(somefunction());
so that I can exploit lateInit to check if a parameter which is required, it’s actually initialized. Do you think is there a better approach when it comes to writing API which are readable for Java as well?v79
04/13/2018, 4:23 PMrequest
(from Spark-Kotlin). It started with val person = Form(request,Person::class).get() as Person
. Then i created an extension function val person = request.bind(Person::class) as Person
. Latest version uses reified generics val person = request.bind<Person>()
. Are there any clear problems using the reified generic extension function approach?visakha
04/13/2018, 5:12 PMRuckus
04/13/2018, 5:25 PMnfrankel
04/14/2018, 7:24 AMfun main(args: Array<String>) {
val client = Client("url", "key", "secret")
fun Command.execute() = client.execute(this).third.fold({ println(it) }, { throw it })
ListVolume().execute()
ListFirewallRules().execute()
}
i would like to have it at the end, as an implementation detail
anyone can confirm?
and tell me whether i can do it otherwise to make it more readable
also, i would be interested in the reason
and if it might change in the futureMarcel Overdijk
04/14/2018, 11:37 AM!!
operator here. I wonder if there is bettter, idiomatic way to do this with Kotlin?BRIAN256
04/14/2018, 3:39 PMgroostav
04/14/2018, 5:02 PMmplacona
04/14/2018, 9:08 PMegordeev1
04/15/2018, 12:01 PMgoto1134
04/15/2018, 1:29 PMylemoigne
04/15/2018, 7:57 PMjava.lang.IllegalAccessError: tried to access field ....
at runtime, all is green in the idea. (using kotlin 1.2.31). Should I fill an issue ?brescia123
04/16/2018, 8:26 AMpublic inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean
with my colleagues and I realized that a lot of them have different intuitive expectations about the output of the function when called on an empty list. Can you provide some insights about the decision of make it return true
if the list is empty? Thanks!hhariri
04/16/2018, 9:55 AMstephanc
04/16/2018, 12:02 PMstephanc
04/16/2018, 12:02 PMstan0
04/16/2018, 12:37 PMstephanc
04/16/2018, 12:45 PMwaqas
04/16/2018, 4:33 PMstephanc
04/17/2018, 7:21 AMwaqas
04/17/2018, 8:51 AMstephanc
04/17/2018, 8:52 AM