Tag: 科特林

Kotlin superClass Kclass

我有这个function的定义 abstract class AbstractDao(private val dataStore: KotlinEntityDataStore): Dao where T: Persistable 我需要从T型获得KClass 。 Kotlin有可能吗?

在kotlin中设置UserDefaultsKeys(swift)

如何在kotlin中设置UserDefaultsKeys(swift)。 将喜欢设置用户数据和登录状态。 一个快速的例子 //swift example; how is this possible with kotlin? set(value, forKey: UserDefaultsKeys.userid.rawValue) synchronize()

习惯性的Kotlin正则expression式

Kotlin正则expression式与解构相匹配有没有更好看的forms? val text = “”” a 10 rows; 120 columns b “”” val columns = “(\\d+) rows; (\\d+) columns”.toRegex(RegexOption.MULTILINE).find(text)?.destructured?.let { (height, width) -> width.toIntOrNull() } ?: 90

Kotlin – kotlin是否包含像java中的基类对象类?

在我的代码我定义下面的variables, var obj_str: Object = “NEW” as Object 这给出警告This class shouldn’t be used in Kotlin. Use kotlin.Any instead This class shouldn’t be used in Kotlin. Use kotlin.Any instead 所以,我需要知道任何类似于kotlin中的对象或其他东西? 还需要知道等待方法如wait(),notify()等在Object类中可用但不在Any中,那么在kotlin中执行该操作?

Kotlin – 了解吸气者和安慰者

Kotlin自动生成它的getters和设置,但我从来没有提到他们? 另外,在Kotlin编写自定义getter / setter的正确方法是什么? 当我说myObj.myVar = 99我觉得myVar是我直接访问的myObj的公共字段? 这里究竟发生了什么?

Kotlin anonim类实现接口

我的kotlin界面: interface IRunnable { fun doWork(): T } 然后我创建匿名类实现我的界面: executor!!.execute(object : IRunnable { override fun doWork(): Long { return 0L } }) 如果在java中的接口,代码看起来像 executor!!.execute(IRunnable2 { return@IRunnable2 0L }) 任何想法,如何实现接口像Java一样的kotlin?

在Kotlin中按多个字段排序收集

比方说,我有一个人名列表,我需要首先按年龄,然后按名称排序。 来自C#的背景,我可以通过使用LINQ轻松实现这种语言: var list=new List(); list.Add(new Person(25, “Tom”)); list.Add(new Person(25, “Dave”)); list.Add(new Person(20, “Kate”)); list.Add(new Person(20, “Alice”)); //will produce: Alice, Kate, Dave, Tom var sortedList=list.OrderBy(person => person.Age).ThenBy(person => person.Name).ToList(); 如何使用Kotlin完成这个工作? 这是我试过的(这显然是错误的,因为第一个“sortedBy”子句的输出被第二个输出覆盖,导致列表按Name排序) val sortedList = ArrayList(list.sortedBy { it.age }.sortedBy { it.name })) //wrong

python vars()在Kotlin中

这个python代码 class Test: def __init__(self): self.one = “python” self.two = “is” self.three = “fun!” t=Test() print(vars(t)) 打印一组字段和它们的值: {‘one’: ‘python’, ‘two’: ‘is’, ‘three’: ‘fun!’}我怎样才能在Kotlin中做同样的事情?

Kotlin函数参考

设records为流/集合,并extract将数据转换为此类集合的元素的函数。 Kotlin有没有办法写出来? records.map {extract(it)} 没有明确地应用(it) ? 例如records.map(extract)或records.map(extract)

未解决的参考sqrt()Kotlin

我想用:( 链接 ) fun sqrt(x: Double): Double 这是我kotlin版本中的一个基本的数学函数: kotlinc-jvm 1.2.0(JRE 1.8.0_151-b12) 其实我的代码是: fun main(args: Array){ println(doSqrt(“16”)); } fun doSqrt(num: String) : String{ var number: Int = num.toInt(); var nb: Double = number.toDouble(); var result: Double = sqrt(nb); return (result.toString()) } 但是当我编译 kotlinc test.kt -include-runtime -d test.jar 结果是: test.kt:10:26: error: unresolved reference: sqrt var result: Double […]