![]() ![]() * * Never equal to null: for any non-null value `x`, `x.equals(null)` should return false. ![]() * * Consistent: for any non-null values `x` and `y`, multiple invocations of `x.equals(y)` consistently return true or consistently return false, provided no information used in `equals` comparisons on the objects is modified. * * Transitive: for any non-null values `x`, `y`, and `z`, if `x.equals(y)` returns true and `y.equals(z)` returns true, then `x.equals(z)` should return true. * * Symmetric: for any non-null values `x` and `y`, `x.equals(y)` should return true if and only if `y.equals(x)` returns true. Implementations must fulfil the following * requirements: * * * Reflexive: for any non-null value `x`, `x.equals(x)` should return true. ** * Indicates whether some other object is "equal to" this one. This means that you can't call toInt() directly on value because it doesn't know that it contains a String at compile time, even though it does at runtime.All three functions are well-known functions which can be overridden in any class. The base keyword can be used with or without parameters. The reason you must cast to a String first is because toInt() is an extension method on String, and value is of type Any?. In this example, the constructor for the base class is called before the block for the constructor is executed. That precisely is what the toInt() method does. The fact that this String represents an integer doesn't matter, as it would need to be parsed into an Int. This isn't working because, as the exception is telling you, value contains a String, and a String cannot be coerced into an Int. The problem is that you were attempting to cast directly from a String to an Int with value as Int. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |