c+ faq - Le Guide et la Liste du livre C+

Mots clés : c++-faqc++c++-faqc++c++-faq

meilleur 3 Réponses c+ faq - Le Guide et la Liste du livre C+

vote vote

97

@NotNull public static String helloWorld() {     return "Hello World"; } 
@Nullable public static String helloWorld() {     return "Hello World"; } 
public static void main(String[] args) {     String result = helloWorld();     if(result != null) {         System.out.println(result);     } } 
void someMethod(@NotNull someParameter) { } 
someMethod(null); 
@Nullable iWantToDestroyEverything() { return null; } 
iWantToDestroyEverything().something(); 
vote vote

80

public void method(Object object) {   if (object == null) {     throw new IllegalArgumentException("...");   } 
public String getFirst3Chars(String text) {   return text.subString(0, 3); } 
if (object == null) {   // something } else {   // something else } 
vote vote

80

public String getPostcode(Person person) {     return person?.getAddress()?.getPostcode();   }   

Questions similaires