https://kotlinlang.org logo
Title
b

bjonnh

06/11/2019, 6:03 PM
how do I get access to the "main" class in a fun main() ? I need to access something like: MySpec::class.java.getResource("/html/file.html").readText()
s

Shawn

06/11/2019, 6:11 PM
the name of the file should do
like if you have your
main()
defined in a file called
Application.kt
, try referencing
ApplicationKt
or, well, that might actually only work from Java
from within
main
, just
this::class
might work
b

bjonnh

06/11/2019, 6:25 PM
this is not defined in this context
I just made an empty class with the same package and am using that
s

Shawn

06/11/2019, 6:33 PM
whoops, never mind then lol
r

Ruckus

06/11/2019, 7:21 PM
You should also be able to use
object{}.javaClass.getResource(...)
Note: Those are curly braces after object, not parenthesis
k

karelpeeters

06/11/2019, 8:02 PM
If you just want any semi-related class
::main::class
works too, it's a class defined in the same package called
TestKt$main$x$1
.
💯 3
b

bjonnh

06/11/2019, 8:09 PM
great, thx