jlleitschuh
09/26/2018, 8:13 PM-Xjsr305=strict enabled and you have a java class annotated with: @ParametersAreNonnullByDefault.
If that class overrides equals(Object other) without having @Nullable on the other param, kotlin can't use the == operator.
Eg. The following won't compile:
JavaSomething("one") == JavaSomething( "one")
Java side:
@ParametersAreNonnullByDefault
public class JavaSomething {
private final String something;
JavaSomething(String something) {
this.something = something;
}
@Override
public boolean equals(final Object other) {
if (this == other) return true;
if (other == null) return false;
if (this.getClass() != other.getClass()) return false;
final JavaSomething javaOther = (JavaSomething) other;
return something.equals(javaOther.something);
}
}Andreas Sinz
09/26/2018, 8:45 PMjlleitschuh
09/26/2018, 8:45 PMAndreas Sinz
09/26/2018, 8:52 PM== requires you to have a equals(other: Any?): Boolean, but you only have equals(other: Any): Booleanjlleitschuh
09/26/2018, 9:00 PMAndreas Sinz
09/26/2018, 9:25 PMthis.equals(other)Dico
09/26/2018, 10:17 PMAndreas Sinz
09/26/2018, 11:08 PMDico
09/27/2018, 3:36 AM== operator.
I mean that, when it tries to find fun equals(Any?): Boolean, it should realize that the method you declared is matching it because the not-null constraint it declares is invalid.Andreas Sinz
09/27/2018, 7:23 AM@NotNull annotation on purpose and doesn't handle the null-case inside equals? Kotlin can't just assume that @NotNull is invalid hereDico
09/27/2018, 7:24 AMequals.Dico
09/27/2018, 7:25 AMAny at compile time, there wouldn't be a problem. It's really the library author's fault if they don't carry over nullability.Andreas Sinz
09/27/2018, 7:30 AMother is actually nullable, because Java doesn't care about annotationsAndreas Sinz
09/27/2018, 7:30 AMAndreas Sinz
09/27/2018, 7:32 AMAndreas Sinz
09/27/2018, 7:33 AM== could be changed so that it checks other == null first, but is it worth it when the library is at fault?Dico
09/27/2018, 7:33 AMDico
09/27/2018, 7:34 AM