Reputation
311
Top tag
Next privilege 500 Rep.
Access review queues
Badges
1 5
Newest
 Critic
Impact
~10k people reached

  • 0 posts edited
  • 0 helpful flags
  • 24 votes cast
Jul
9
comment Java's Boolean class - why not an enum?
"For foo, I just get a warning about boxing an already boxed value. However, the code for bar is a syntax error:" This is an incorrect comparison. In Boolean.valueOf(Boolean.valueOf("TRUE")), there are two different valueOf methods: valueOf(String) and valueOf(boolean). The syntax error is because you forgot to implement the valueOf(boolean) in MyBoolean. Then there's the autounboxing between the two calls, which is hardcoded in the language for Boolean but not MyBoolean.If you implemented valueOf(boolean) MyBoolean.valueOf(MyBoolean.valueOf("FALSE").booleanValue()) works
Jul
9
comment Java's Boolean class - why not an enum?
"But... there's a problem here. You can't override a static method." You are not "overriding" anything -- the method doesn't exist in a superclass anyway. The problem instead is that the method is automatically defined for all enums, and you cannot redefine it.
Jul
5
answered Why isn't the isa pointer hardwired in Objective-C classes?
Jun
23
answered @SuppressWarnings in generic array declaration
Jun
9
comment Parameters are passed by value, but editing them will edit the actual object (like passed by reference)?
"When an objects is passed into a method as a parameter," "Objects" are not values in Java (there are no "object types") and cannot be "passed". If you can explain that, then everything else follows.
Jun
9
comment Parameters are passed by value, but editing them will edit the actual object (like passed by reference)?
"When you pass an object to a method" It doesn't really make sense to say "pass an object", because "objects" are not values in Java. Syntactically, you can only pass expressions, and every expression has a compile-time type, and there are no "object types" in Java, so whatever you are passing, it's not "an object". It's something else.
May
20
comment return a object without returning the reference
"Objects" are not values in Java (there are no "object types" in Java). Everything that is not a primitive is a reference. You cannot return "an object" or "a list of objects". You can only return "a reference" or "a reference to a list of references". Objects can only be manipulated through references.
May
7
answered Legitimate cases of having .equals() behaving inconsistently with .compareTo()?
Feb
27
comment What argument passing mechanism does python use, and where is this officially documented?
That's exactly what's called pass-by-value -- passing works the same way as assigning.
Feb
5
comment Overriding equals() method in Java
@InstructedA: Adding lots of special cases for particular methods to the language is bad design.
Feb
5
comment Overriding equals() method in Java
@InstructedA: Those interfaces don't specify any methods. (They are called "marker interfaces".) There is nothing special about that. Anyone can make any number of interfaces that don't have any methods.
Feb
5
comment Overriding equals() method in Java
@InstructedA: There is nothing special compiler-wise about Cloneable and Serializable, except that arrays automatically implement both.
Feb
4
comment Overriding equals() method in Java
@InstructedA: There is no syntax or construct in Java (or any other language AFAIK) to make a method "overrideable once, but the override cannot be overridden" without the override choosing it as such.
Feb
4
comment Overriding equals() method in Java
If Object.equals() were not overrideable, then it would be the same as ==, and so would be redundant and unnecessary.
Jan
17
awarded  Critic
Dec
13
comment Why use arg type `class Object` instead of `Comparable[]`?
"By the way, let's forget about generics for a moment: after all, early versions of Java, for which sort was implemented, did not provide generics." But the question doesn't have anything to do with generics -- both Object[] and Comparable[] are non-generic. So the "early versions of Java" could use Comparable[].
Dec
13
comment Why use arg type `class Object` instead of `Comparable[]`?
"Both checks can be done at runtime" If by "checked at runtime" you mean, try it and see if it throws an exception, then yes. Otherwise, #2 is not guaranteed to be checkable at runtime.
Dec
13
comment Why use arg type `class Object` instead of `Comparable[]`?
"one can be safe from runtime exceptions because every passed object has to implement interface Comparable" That would still not be safe from runtime exceptions. In order to sort, you need to make sure that the type is comparable to itself. You need a bound like <T extends Comparable<? super >>. Otherwise, it is still not safe. You will still get a warning.
Dec
10
comment Why is the hashCode method usage of HashSet not specified in the API?
@RossPatterson: Right, because sets and maps are analogous and can be implemented in terms of one another.
Dec
9
comment Why is the hashCode method usage of HashSet not specified in the API?
@RossPatterson: Well, it has to use .hashCode(), because the point of using HashSet is that it has average-case constant complexity for lookup, insertion, and deletion. And that is only possible if it uses .hashCode() for a hash table.