我想要编译与Oracle JDK 1.8的简单代码:java中的NotNull在哪里?
class Foo {
public static void test(@NotNull String a) {}
}
但idea
不明白这样的代码,并建议增加:
import com.sun.istack.internal.NotNull;
在编译后内部idea
作品, 但如果运行通过gradle
搭建build.gradle
:
version '1.0-snaphshot_03.03.2017'
apply plugin: 'java'
targetCompatibility = '1.8'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
artifacts {
archives sourcesJar
}
我得到错误:
error: package com.sun.istack.internal does not exist
import com.sun.istack.internal.NotNull;
error: cannot find symbol
public static void test(@NotNull String a) {
^
symbol: class NotNull
location: class Foo
我认为NotNull
在1.8
加入? 我如何才能使在idea
和gradle
?
请检查http://stackoverflow.com/questions/4963300/which-notnull-java-annotation-should-i-use。我认为这是@NonNull。 – SachinSarawgi
你的意思是'javax.annotation.Nonnull'吗? – QBrute
试试可选。 –
MicD