Skip to content

Commit

Permalink
Update some code
Browse files Browse the repository at this point in the history
  • Loading branch information
wlybe committed Nov 9, 2023
1 parent e077b7b commit c0962ec
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions material/samples/app/src/main/java/null_safety_java/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
public class App {

public static void main(String[] args) {

int length = getLength(null);

@Nonnull
String name;
name = null; // warning
Expand All @@ -19,9 +22,14 @@ public static void main(String[] args) {
System.out.println(name2 == null ? 0 : name2.length());
}

public static int getLength(String name) {
return name.length();
}

public static int getLength2(@Nullable String name) {
if (name == null)
return 0;
return name.length();
}

}

0 comments on commit c0962ec

Please sign in to comment.