java Kotlin:未解决的参考:javaClass

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27520828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 11:56:09  来源:igfitidea点击:

Kotlin: Unresolved reference: javaClass

javakotlin

提问by HairyLemon

I'm hoping someone has come across the issues that i'm seeing while building my java/Kotlin project. The project is interop with java and kotlin, with the following versions:

我希望有人在构建我的 java/Kotlin 项目时遇到过我遇到的问题。该项目与java和kotlin互操作,有以下版本:

  • Jdk 1.7
  • Kotlin 0.9.66
  • Gradle (wrapper) 2.0
  • JDK 1.7
  • 科特林 0.9.66
  • Gradle(包装器)2.0

Kotlin has been compiling fine prior to a few changes i made i.e. converted a few java classes to equivalent kotlin versions.

在我进行一些更改之前,Kotlin 一直编译得很好,即将一些 Java 类转换为等效的 kotlin 版本。

Here are the errors that i'm seeing:

以下是我看到的错误:

  c:\projects\myproject>gradlew  :java:workspace:models:compileKotlin  --stacktrace     :java:workspace:models:compileKotlin

w: Annotations path entry points to a non-existent location:
C:\projects\myproject\java\workspace\models\annotations

e: C:\projects\CustomerProfileEmail.kt: (15, 32): Unresolved reference: toLowerCase
e: C:\projects\CustomerProfilePhone.kt: (34, 22): Unresolved reference: equalsIgnoreCase
e: C:\projects\Account.kt: (17, 21): Unresolved reference: javaClass
e: C:\projects\Account.kt: (18, 21): Unresolved reference: javaClass
e: C:\projects\Account.kt: (31, 15): Unresolved reference: indexOf
e: C:\projects\Account.kt: (35, 15): Expression 'length' of type 'kotlin.Int' cannot be invoked as a function. The function invoke() is not found
e: C:\projects\Account.kt: (39, 15): Expression 'length' of type 'kotlin.Int' cannot be invoked as a function. The function invoke() is not found
e: C:\projects\Balance.kt: (10, 21): Unresolved reference: javaClass
e: C:\projects\Balances.kt: (12, 21): Unresolved reference: firstOrNull
e: C:\projects\Balances.kt: (12, 35): Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) -> ...} notation
e: C:\projects\Debit.kt: (7, 12):Unresolved reference: javaClass
e: C:\projects\ProgramR.kt: (12, 21): Unresolved reference: javaClass
e: C:\projects\ProgramR.kt: (13, 21): Unresolved reference: javaClass
e: C:\projects\Transaction.kt: (7, 12): Unresolved reference: javaClass
e: C:\projects\Transaction.kt: (7, 40): Unresolved reference: javaClass
e: C:\projects\Adjustment.kt: (13,21): Unresolved reference: javaClass
e: C:\projects\Reward.kt: (12, 24): Unresolved reference: javaClass
:java:workspace:models:compileKotlin FAILED

FAILURE: Build failed with an exception.

Here is an example of the source code:

这是源代码的示例:

import javax.xml.bind.annotation.*

XmlAccessorType(XmlAccessType.FIELD)
XmlType
XmlSeeAlso(javaClass<LoyaltyCredit>(), javaClass<Debit>())
public open class Transaction: TransactionParent(){
    public var account: Account? = null
    public var balances: Balances? = null
    public var rewards: Rewards? = null
}

Gradle script

摇篮脚本

repositories {
    mavenCentral()
}

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.connorgarvey.gradle:gradle-grails-wrapper:1.0'
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.9.66'
        classpath 'org.jetbrains.kotlin:kotlin-stdlib:0.9.66'
    }
}

apply from: 'build/includes.gradle'

I have already seen this: https://devnet.jetbrains.net/message/5478050didn't help.

我已经看到了这个:https: //devnet.jetbrains.net/message/5478050没有帮助。

Any help would be greatly appreciated!

任何帮助将不胜感激!

采纳答案by user2235698

Compare your script with Kotlin referenceabout Gradle.

将您的脚本与关于 Gradle 的Kotlin参考进行比较。

Kotlin Stdlib dependency should be in another scope, not buildscript. Also Kotlin plugin should be applied using apply plugin.

Kotlin Stdlib 依赖项应该在另一个范围内,而不是buildscript. Kotlin 插件也应该使用apply plugin.