Tag Archives: Java

Java Abuse: Inline instanceof

One annoyance in Java is having to do instanceof checks on multiple lines. e.g.

if (object instanceof Foo) {
Foo foo = (Foo)object;
foo.foo();
}

While this is often a sign of a design failure, there are times when instanceof checks are required often due to framework constraints etc. The above is [...]

Posted in Java, Uncategorized | Tagged | 4399 Comments

Java Abuse – Currency Pattern

Here’s a sillier one from last night…
People often complain about not being able to return multiple values from a method in Java. I can’t see a good reason for wanting to do this, but some do.
The example I was given was wanting to do:

int foo, bar, baz; list(foo, bar, bar) = func(ponies);

Where func(ponies) returns 3 [...]

Posted in Java | Tagged | 1537 Comments

Java Abuse – Ternary Try/Catch

We often discuss Java limitations on IRC and try to come up with (sometimes silly) workarounds. Unfortunately after time passes it’s often easy to forget the outcome, and lose code snippets. So I thought I’d start blogging some of them so I don’t lose them, and other people might suggest other ways of doing things [...]

Posted in Java, Uncategorized | Tagged | 3480 Comments