I want to compile simple code with oracle jdk 1.8:
class Foo {
public static void test(@NotNull String a) {}
}
But idea
not understand such code, and suggest to add:
import com.sun.istack.internal.NotNull;
after that compilation inside idea
works,
but if run build by gradle
with such 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
}
I got error:
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
I thought that NotNull
was added in 1.8
?
How can I make possible of usage of NotNull
in idea
and gradle
?
notNull() is a static method of the Validate class that is used to check whether the passed object is null or not. If the passed object is null , then the method raises an exception with a formatted message. If the passed object is not null , then the method returns the input as it is.
The @NotNull Annotation is, actually, an explicit contract declaring the following: A method should not return null. A variable (like fields, local variables, and parameters) cannot should not hold null value.
Null is a reserved keyword in the Java programming language. It's technically an object literal similar to True or False. Null is case sensitive, like any other keyword in Java. When programming in Java, it's important to write null in lowercase.
There is no @NotNull
annotation in the standard JDK that would be meant for general use (the com.sun.internal.istack.NotNull
is definitely not for your usage, as it's an internal class).
The Java Bean validation framework (JSR-303) has javax.validation.constraints.NotNull
, which is implemented by (for example) Hibernate validator. That's probably what you're looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With