Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java equals()

Name: Anonymous 2009-05-18 5:38

I want to put an equals() method in all of mine immutable (final) classes.
Should I use the instanceof or the getClass() approach?

thanks!

Name: Anonymous 2009-05-18 5:43

Its Java, always use the most retarded refelection techniques to ensure you program runs as slow as possissible.

Make an equal factory, then grow up and ditch your faggy Java shit.

Name: Anonymous 2009-05-18 5:58

It depends on what exactly you are doing. Sometimes it is appropriate to use instanceof and sometimes not. For instance, consider a square class that extends a rectangle class. Clearly a square of width 5 should be considered 'equal' to a rectangle of width 5 and height 5, regardless of whether or not they are the same class, in this case instanceof is appropriate. Then consider a "Health Professional" class which has two subclasses, a "Surgeon" and a "Nurse." Suppose equality of health professionals is define by their experience and number of peer reviewed publications. Does that mean a surgeon and a nurse both with ten years of experience and six published papers are equal? Certainly not, the surgeon is far more skilled and likely has ten nurses lining up to suck his dick, so here getClass() would be appropriate. If you are really stuck post what classes you are modelling and I'll have a look.

Name: Anonymous 2009-05-18 6:04

>>3

What he means is, use a true class based object oriented system. Java is not. Class based OOP demands that everything is an object. You should now realize why this is. Java does not. See: int versus Integer.

Ditch your shitty poorly thought out langauge/framework for something that wasn't coded using the million monkey principal.

Name: Anonymous 2009-05-18 6:07

For instance, consider a square class that extends a rectangle class.

Hoo, boy.  A standard interview question you just flunked!

Name: Anonymous 2009-05-18 6:09

>>4
monkey principal
What a silly high school you went to.

Name: Anonymous 2009-05-18 6:17

>>6

Apparently I actually got an education while your Indian school did not.

Name: Anonymous 2009-05-18 6:23

>>7
My Indian school did not get an education?

Name: Anonymous 2009-05-18 7:56

>>3

OP here. I'm making a simple
public final class Time implements Comparable<Time> with only a couple of fields (hours, minutes, seconds).
// The teacher said to keep it simple (lulz).

Name: Anonymous 2009-05-18 7:58

lulz
Back to /b/

Name: Anonymous 2009-05-18 8:00

>>10

Sorry, it's the habit.

Name: Anonymous 2009-05-18 12:11

>>4
>>See int versus Integer

lost me there. You are retarded

Name: Anonymous 2009-05-18 12:44

>>3
Surgeon is not a subclass of Man, and is not guaranteed to have a publically accessible Dick object.
I suggest wrapping the Surgeon Object in a adapter before passing it to serve the NurseQueue.

Name: Anonymous 2009-05-18 17:03

>>5
Anybody who thinks rectangle should extend square is just plain retarded.

Name: Anonymous 2009-05-18 17:05

>>14
A rectangle is a special case of a square (ie. it's a square with irregular sides)

Name: Anonymous 2009-05-18 17:14

>>15
0/10

Name: Anonymous 2009-05-18 17:29

>>14-15
Neither should extend the other. Haven’t you read your Behavioral Subtyping Using Invariants and Constraints today?

I think that's what >>5-san was saying.

Name: Anonymous 2009-05-18 18:40

>>17
It appears to take the atypical argument that because a square cannot do everything a rectangle can do it can't be a subclass. This is entirely false- namely because the premise is false and the scale(double x, double y) method is a good example of this. It's argued a rectangle would have such a method but a square cannot have such behavior because it would no longer be a square. What is wrong here is assuming any class of a rectangle when scaled is still that same class of a rectangle, not that the square can't satisfy the specified behavior. The solution would be a mutable Shape system, and then having scale return an object of type Shape or Rectangle- not simply attempt to transform a Square.

Name: Anonymous 2009-05-18 18:42

>>18
mutable
Change that to immutable.

Name: Anonymous 2009-05-18 20:12

>>18
Why not use matrices rather than double

Name: Anonymous 2009-05-18 21:26

>>20
Maybe because if you're doing arbitrary affine tranforms, you won't want to have classes for different shapes anyway?

Name: Anonymous 2009-05-18 21:28

>>1-21
Cut the ENTERPRISE QUALITY bullshite and use whatever works.

Name: Anonymous 2009-05-18 22:06

>>22
But it probably doesn't. You'll have four guys write 5000 LoC each, and then you discover you'll have to rewrite it all because the code is ugly and full of hacks, and it can't be made to work the way you need it to no matter what.
And then you rewrite it as a couple of 500 line unmantainable Perl scripts that no one will dare touch in 10 years because they kind of work, despite some small work-aroundable issues.

Name: Anonymous 2009-05-19 3:09

>>20
Great way to dodge the argument. Mind actually telling me why I am wrong? I realise that could well be the case but in the interests of being scientific and ultimately constructive it would be nice if you actually elaborated on why.

Name: Anonymous 2009-05-19 3:56

>>20
>>21
Why not use java.awt.geom.Rectangle2D.Double and java.awt.geom.AffineTransform along with public Shape createTransformedShape(Shape pSrc) instead of reinventing the wheel?

Name: Anonymous 2009-05-19 4:47

OP RELATED THREAD

Name: Anonymous 2009-05-19 5:33

>>12

Speaking of retarded you shit heating faggot, in Java int is a "primitive" type. It is not an Object. Integer is an object type. It is the object type for int.

So Sun implemented efficient primitive types with Object implementations.

Instead of doing the fucking right thing and make all types Objects that are efficient.

Name: Anonymous 2009-05-19 5:54

>>27
This might surprise you but javas "primitive" integers exhibit intelligent autoboxing behaviour, in fact. A primitive integer could even be considered a wrapper around its Integer object that simply hides all the details until neccesary- what better effeciency could you ask for? On the subject of effeciency, java arithmetic is actually benchmarkedly faster than Se and Sepples arithmetic, a testament to the sound design decisions of the Sun Java team.

Name: Anonymous 2009-05-19 6:53

Name: Anonymous 2009-05-19 6:58

>>29
I love Xarn.

Don't change these.
Name: Email:
Entire Thread Thread List