This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void FilterClickShouldChangeRecyclerViewCount() { | |
// Get items count before action | |
RecyclerView recyclerView = mActivityTestRule.getActivity().findViewById(R.id.recycler_view); | |
int countBefore = Objects.requireNonNull(recyclerView.getAdapter()).getItemCount(); | |
Log.e("count", "Items count before: " + countBefore); | |
// Perform action | |
ViewInteraction actionMenuItemView = onView( | |
allOf( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String someStr1 = ""; // initialized with empty string | |
String someStr2; // by default value of someStr2 is null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nullableStr: String? = null | |
var nonNullStr: String = "a string" | |
nullableStr = nonNullStr // valid | |
nonNullStr = nullableStr // error, should be checked for nullability first | |
If (nullableStr != null) { | |
nonNullStr = nullableStr // valid | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Integer intObj = null; | |
int primitiveInt; | |
primitiveInt = intObj; // NullPointerException during unboxing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val someStr1: String = "" // same as in Java, i.e initialized with empty string | |
val someStr2: String // warning: no default value assigned. Should be initialized | |
// with a non-null value before its first use | |
val someStr3: String = null // error: can't be null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class Test(val someInt: Int) | |
val test1: Test // warning: no default value, should be initialized | |
// with non-null value before first use | |
val test2: Test = null // error: non-nullable type can't hold null value | |
val test3: Test? = null // valid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val someStr1: String? = null // valid statement, notice a question mark after 'String' | |
val someStr2: String? // warning: no default value assigned. Should be initialized | |
// with some (nullable or non-nullable) value before its first use |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nonNullInt = 1 | |
val nullInt: Int? = null | |
// 1. Error | |
nonNullInt = nullInt // Error: type mismatch | |
// 2. Valid | |
if (nullInt != null) { | |
/* Here is used a smart cast (one of Kotlin compiler's feature), | |
which casts Int? to Int automatically */ | |
nonNullInt = nullInt | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Integer nullInt = null; | |
if (someInt.equals(23)) { // NullPointerException because of attempt to call | |
// a method on a null | |
// Rest of code | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val nonNullInt = 1 | |
val nullInt: Int? = null | |
if (nullInt == nonNullInt) { | |
println("Both are equal") | |
} else { | |
println("Not equal") // Result is 'Not equal' | |
} |
OlderNewer