Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
My Brazilian ass cannot comprehend tip culture at all.
Tenary operator explanation was the key in this context - thanks.
Assuming you're more familiar with C#:
intin Java is a primitive type, which is akin to what C# calls value types;intaliasInt32is a value type in C#. They cannot benullin either language, they always hold a value.Integerin Java on the other hand is a boxed integer, which is an object (what C# calls a reference type) that CAN benull. The closest thing C# has is nullable types:int?. Boxed types are usually mixable with primitives because the Java compilers performs auto-unboxing (i.e. converting back to a primitive) as needed.Now to the particular error you're getting (
Cannot invoke "java.lang.Integer.intValue()"): this is a well-known quirk of the ternary operator in Java. Your code boils down to this:Here the specifications for the ternary operator say that the nested ternary has type
Integer, because the first option1is anintso the second optionnullis interpreted as a null reference of typeInteger(it's the only way to make those two options compatible). But for the outer ternary, the reverse happens:intas first option,Integeras the second. The compiler does not know that the second option isnull, it auto-unboxes it to a primitiveint, so you get aNullPointerException.It's as if you had written:
You have a detailed explanation of the relevant rules in the stack overflow thread I linked.
null as Integer? => NullPointerException
i do understand the Java is a higher state of mind - but null as Integer?
python round() is screwing the results up
warning cleared
Thanks. It was just a typo. Have a nice day;
Your solution has a bug, it is not a kata issue.
This comment is hidden because it contains spoiler information about the solution
like this one
Enabled in this fork
Duplicate?
Remove those silly arguments checks. If you do keep them in for some reason, change the return type. We now have mixed return types :/
Java fork (author inactive)
Integerconstructor, which triggers deprecation warnings (fixing this issue)Loading more items...