Michał Kalinowski
10/17/2019, 3:36 PMoverride fun toString()
, and now I would like make constructor(type: String)
that will create enum from appropriate string, anyone have idea how to accomplish such thing?ursus
10/19/2019, 2:56 AMA: fun foo(parentId: Long, itemId: Long)
B: fun foo(itemId: Long, parentId: Long)
Tuang
10/19/2019, 1:15 PMQueryRunner().query()
return Long
, is it depending on what Handler is using?
For example my code is like this
val query = "SELECT COUNT(*) FROM goods_user_rel WHERE _goods_id = ?"
val count = QueryRunner().query(connection, query, ScalarHandler<Long>(), goodsId)
The first time i wrote ScalarHandler<Int>()
and i got error something likes java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
Then i change ScalarHandler<Int>()
to ScalarHandler<Long>()
and it’s work but i have no idea why Long
is returnTuang
10/20/2019, 12:05 AMclass Myclass(val name: String, val age: Int) {
private someProperty = .....
private someProperty = .....
companion object {
@JvmStatic
val instance = Myclass(name = ?? , age = ??)
}
}
how to set name and age value inside the companion object?Florian
10/20/2019, 5:05 PMtoffe
10/21/2019, 10:44 AMArnau Díaz
10/22/2019, 8:13 AMabstract class ParentObject(val id: Int)
class ChildObject(id: Int, val value: String) : ParentObject(id)
With adt/sealed class it doesn't compile:
sealed class ParentObject(val id: Int)
data class ChildObject(id: Int, val value: String) : ParentObject(id)
Is there any way to get it working in Kotlin? I want the benefits of the data classes but there are some fields that are common for all my subtypes.eekboom
10/22/2019, 10:04 AMinterface Foo { val text: String }
class Bar (private var text2: String) : Foo {
init {
text2 = text2.replace('a', 'z')
}
override val text: String
get() = text2
}
LastExceed
10/22/2019, 10:11 AMscottiedog45
10/22/2019, 5:03 PMdata class Foo(val a: String) {
init {
//magic that takes string and sets it to a
}
}
var Bar : Foo = "b"
Peter
10/22/2019, 6:01 PMSandeep Kumar
10/22/2019, 11:18 PM@Controller
class FileServerController {
@RequestMapping(value = ["/**"])
fun getFile(request: HttpServletRequest, response: HttpServletResponse): FileSystemResource {
var fileName = request.servletPath
val HOME = System.getenv("HOME")
println("Requested ${fileName}")
fileName = "${HOME}${fileName}"
val file = File(fileName)
if (file.canRead()) {
println("Serving ${fileName}")
if(fileName.endsWith(".xml")) {
response.contentType = "text/xml"
} else if(fileName.endsWith(".xslt")) {
response.contentType = "application/xslt+xml"
}
return FileSystemResource(file)
} else {
println("Couldn't find ${fileName}")
throw NotFoundException(fileName)
}
}
}
The dependencies in my pom.xml are
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
Pranjal Desai
10/23/2019, 7:05 PMFlorian
10/26/2019, 1:35 PMFlorian
10/28/2019, 8:55 AMMatheus
10/28/2019, 8:31 PMClass<T>
return type, but I can't seem to make it work with nullable types without triggering a compiler warning
override fun toType(): Class<Boolean?> =
Boolean::class.java as Class<Boolean?>
This works, but the cast triggers the warning: Unchecked cast Class<Boolean> to Class<Boolean?>
I tried to qualify it as <out Boolean>, but I can't seem to make it work?Florian
10/29/2019, 10:16 AMInt?
uses Java's Integer
class?vlad.minaev
10/30/2019, 10:23 PMfun <T : User>gen(): List<T> = listOf(User())
antoniomarin
11/01/2019, 10:08 AMuserLocation
. This code wont work, because it.userlocation.forEach
will loop through string characters but you get an idea what I’m trying to doleosan
11/01/2019, 4:46 PMval listOfLists = listOf(
Data(1, listOf("A")),
Data(2, listOf("B")),
Data(1, listOf("B")),
Data(2, listOf("C"))
)
output: [ Data(1,listOf("A","B")) , Data(2,listOf("B","C"))]
morozov
11/02/2019, 7:13 PMtarget?.let { targetList.sortedWith(compareBy {it.priority == 1})}
Harsh Rathod
11/05/2019, 9:28 AMFrodrigues
11/05/2019, 3:33 PMGoose
11/05/2019, 3:43 PMFrodrigues
11/05/2019, 9:42 PMColton Idle
11/06/2019, 4:15 AMinterface SaveListener {
fun onSave(name: String)
}
MY ISSUE: When I try to create the listener, it makes me write out the whole thing. I thought there was a way around this in Kotlin? Probably missing something basic.
So I have to write this
myController.listener = object : SaveListener {
override fun onSave(name: String) {
//do thing
}
}
But with kotlin I thought I'd be able to do this
myController.listener = SaveListener { //do thing }
andrzej
11/06/2019, 9:00 AMMani
11/06/2019, 10:07 AMval pickableState = try {
PickableState.valueOf(state)
} catch (ex: Exception){
null
}
Jesse Stolwijk
11/06/2019, 10:21 AMPickableState.values().singleOrNull { it.name == state }
scottiedog45
11/06/2019, 12:36 PMz
is a textView:
z.text = z.context.getString(R.string.empty)
scottiedog45
11/06/2019, 12:36 PMz
is a textView:
z.text = z.context.getString(R.string.empty)
tseisel
11/06/2019, 1:11 PMContext
that outlives the `Fragment`/`Activity` where the View
is defined (this would result in memory leaks).
Note that in your sample code, you could have used z.setText(R.string.empty)
, which internally does what your code is doing : accessing resources from its Context.Alex Crafford
11/06/2019, 1:23 PMz.text = resources.getString(R.string.empty)
or
z.text = ""
scottiedog45
11/06/2019, 1:29 PMcontext
parameter:
fun replaceEmptyDataWithLiteralEmptyStringIfNeeded(c: Context, textViews: List<TextView>, data: List<String?>) {
(textViews zip data).forEach { z ->
if (!z.second.isNullOrEmpty()) {
z.first.text = z.second
z.first.setTypeface(null, Typeface.NORMAL)
} else {
z.first.text = c.getString(R.string.empty)
z.first.setTypeface(null, Typeface.ITALIC)
}
}
}
Alex Crafford
11/06/2019, 1:31 PMscottiedog45
11/06/2019, 1:32 PMgetString
. Ah- that empty string is literally the word “empty” 😅Alex Crafford
11/06/2019, 1:33 PMscottiedog45
11/06/2019, 1:34 PMAlex Crafford
11/06/2019, 1:37 PMscottiedog45
11/06/2019, 2:01 PM