I'm having trouble referencing a kotlin object from another package.
Here's some relevant info from docs:
Note that anonymous objects can be used as types only in local and private declarations. If you use an anonymous object as a return type of a public function or the type of a public property, the actual type of that function or property will be the declared supertype of the anonymous object, or Any if you didn't declare any supertype. Members added in the anonymous object will not be accessible.
I'm able to compile and pass tests within intellij, but not from the cli. Any advice?
$ ./gradlew test
...
Caused by: java.lang.NullPointerException at TokensTest.kt:27
// src/DB.kt
package geofflangenderfer
object DB {
private val host = "localhost"
private val port = 8080
private val dbName = "tokens"
private val dbUser = "postgres"
private val dbPassword = "postgres"
fun connect(): Database {
return Database.connect(
url="jdbc:postgresql://$host:$port/$dbName",
driver="org.postgresql.Driver",
user=dbUser,
password=dbPassword
)
}
}
// test/tokens/TokensTest.kt
package geofflangenderfer.tokens
import geofflangenderfer.DB
class TokensTest {
@BeforeEach
fun cleanup() {
DB.connect() // this results in NPE
transaction {
addLogger(StdOutSqlLogger)
SchemaUtils.drop(Tokens)
SchemaUtils.create(Tokens)
}
}
}
question from:
https://stackoverflow.com/questions/65876094/null-pointer-unresolved-reference-issue-with-kotlin-object 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…