want to implement a function similar to that in js
require(["a", "b", "c"], function(a, b, c){
})
ask, how is it written as a parameter in a lambda?
want to implement a function similar to that in js
require(["a", "b", "c"], function(a, b, c){
})
ask, how is it written as a parameter in a lambda?
cannot be written. Refer to https://stackoverflow.com/que.
unfortunately cannot be implemented. As mentioned in the question and answer of StackOverflow provided by codegoose, kotlin's lambda does not provide support for the vararg modifier for the time being
to implement the function definition you need, here are two similar implementations I know
//
interface Cry {
fun crying(vararg x : String)
}
private fun require(vararg config: String, cry: Cry) {
cry.crying(*config)
}
fun test1() {
val config = arrayOf("1", "2")
require(*config, cry = object : Cry {
override fun crying(vararg x: String) = x.forEach(::println)
})
}
// arrayOfvarargArray<out String>
private fun require(vararg config: String, block : (Array<out String>) -> Unit) {
block(config)
block(arrayOf("1", "2", "3"))
}
fun test2() {
val config = arrayOf("1", "2")
require(*config, block = { it.forEach(::println)})
}
I have a data like this { "_double": 2.333, "_float":3.14159, "_int":314, } I will convert _ double to double (not accepted with Double ), and so on. but the data given by the server sometimes looks like...
Can you explain what this line of code means? Why can it be written like this? Why should it be written like this? fun log(tag: String) = fun(target: OutputStream) = fun(message: Any?) = target.write("[$tag] $messa...
FinalTest class FinalTest { public static void main(String[] args) { try { Field field = TestHelper.class.getDeclaredField("ENTITY"); field.setAccessible(true); Entity entity = new Entity("...
the following code will not report an error in Java, but an error will be reported in Kotlin. How to solve it? is that I don t want to care about the generic parameters of the parent class, just inherit it directly in Java. What do I do in Kotlin? J...
is there something wrong with idea s support for spring boot kotlin? use idea to develop spring boot applications. I used to use java,. Now I want to try kotlin (I learned kotlin a long time ago). the front end uses the thymeleaf template engine. ...
I can get it by reflection when I write java. I wonder if there are other convenient ways for kotlin. ...
write the onclick method directly in xml java can directly create a new method in activity kotlin prompts the error org.jetbrains.kotlin.asJava.classes.KtLightClassImpl I don t know which friend has encountered this kind of problem and how to solve ...
because the number of code methods exceeds 65535 and cannot be packaged, I introduced MultiDex subpackages. when I finished packing, one of the kotlin functions that I ran into the class went wrong, causing the program to crash. has looked up a lo...
because the subscribed content must be executed on a new thread, at first I thought I needed to wait to avoid memory leaks, but after that, the memory still leaked < H2 > fragment < H2 > class MemoryLeakFragment : Fragment() { lateinit var dispo...
fun test() { Canvas().bindPaintDrawPoints(Paint())( arrayOf(PointF(1f, 2f), PointF(2f, 2f), PointF(3f, 2f), PointF(4f, 2f)) ) } fun Canvas.bindPaintDrawPoints(paint:...
I have a method that must pass in a fixed object paint every time, because this function is called frequently, so I can t create an object in an inline function. (Canvas.apply(..,..)) bind(pointPaint) drawPoint(poin...
problem description at present, I have made an app, by using the combination of Kotlin and Weex. I want to get all the printers in the local area network and call the printer. Is there any way.. the environmental background of the problems and what ...
import kotlin.reflect.KProperty import kotlinx.serialization.* import kotlinx.serialization.json.JSON.Companion.stringify class Delegate<T: Any>(val key: String, private val default: T) { operator fun getValue(thisRef: Any?, property: KProperty&l...
using Kotlin to develop Spring Boot is to find the following problems. How to solve them? ] ...
following the official description of Anko, I added the following code to my dependency: api "org.jetbrains.anko:anko-commons:$anko_version " then I want to use his startActivity < AAA > () method. Cannot use The project uses Kotlin develop...
what I want to implement is a web service, and requests come in with a lot of filters tagged. My idea now is to make these filters into Vertical, and then communicate all through EventBus. Request to enter the first filter and throw it to the next one af...
start with java code: public class TUtil { public static <T> T getT(Object o, int i) { try { return ((Class<T>) ((ParameterizedType) (o.getClass() .getGenericSuperclass())).getActualTypeArguments...
problem description the front end of the project uses angular and the background springboot. The problem is that no matter how the backend modifies the file format, the file format downloaded at the front end is txt I tested it with excle here, so I ...
problem description running environment MacOS 10.14.3 Android Studio 3.3.1 create a project in AS. The directory of the project is as follows Picture description the dependencies of each module are as follows 1, baselibrary dependencies { ...