27

The main() method in the following Java program is a text rebus. What does it represent?

import java.util.*;
import java.awt.geom.*;

public class WhatDoesMainRepresent {
    private static HashSet<Obj> hashSet = new HashSet<Obj>();
    private static AffineTransform e = new AffineTransform();

    static {
        hashSet.add(new Obj());
    }

    public static void main(String[] args) {
        hashSet.add(new Obj());
        e.rotate(Math.PI);
        {}
    }

    private static class Obj {
        public int hashCode() {
            return 1;
        }
    }
}

Hints:

1. The AffineTransform object is named e for a reason.
2. The hashSet.add(new Obj()) line in the main() method represents a single word that is a verb. (So far that word has not been mentioned.)

pacoverflow
  • 15,204
  • 2
  • 55
  • 94

5 Answers5

24

It represents

Kaleidoscope

Reasoning:

The second add will have the object "collide" with the first on the hashset since they have the same hash code. e rotated 180 degees is "a". The empty curly braces are a new "scope". Collide+a+scope = kaleidoscope.

Person
  • 341
  • 1
  • 3
14

I shame myself with this guess if it turns out to be wrong, but I suspect the text is the idiom

been around the block once or twice

The reasoning being:

Every key/value pair in a hash map is stored in a bin determined by its hash code. In this case the hashcode for all objects of the Obj class is identical, meaning such objects are stored in the same bin.

The e.rotate(Math.PI) statement performs a useless 180° inversion. The transform will therefore turn its operand around. The {} represents an empty block.

The static statement and initial statement in main adds an object to the same bin once and then twice.

Hence: bin around the block once or twice.

After typing this out, I realize how indescribably bad this pun is. I truly hope this isn't the correct answer. :P

COTO
  • 10,083
  • 36
  • 91
  • 1
    No need to worry, that's not the correct answer. :) +1 for a nice explanation though. – pacoverflow Jul 27 '15 at 19:16
  • 2
    After reading that explanation, it's kinda hard to believe this isn't correct. +1 – Set Big O Jul 27 '15 at 19:38
  • @Geobits Well the puzzle does specify that the rebus is the main method, so the static statement won't be a part of the answer, so "or twice" isn't really valid. – pacoverflow Jul 27 '15 at 19:44
  • 2
    If the static statement isn't part of the answer, what is its purpose? The code will function the same without it. – Ian MacDonald Jul 27 '15 at 20:15
  • I think you're right about the "spin around" line. I suspect the last block is more of a "do nothing" than a "block", though. – Bobson Jul 27 '15 at 22:39
  • @IanMacDonald The static statement provides setup for main(). I think that if COTO's answer were the correct answer, then both hashMap.put() calls could be in main() - there'd be no need for a static initialization block. – pacoverflow Jul 28 '15 at 05:18
  • @pacoverflow: Two questions: 1) Is the fact that you're using a hash map with null key instead of a hash set significant? (Strictly speaking, storing null values in a hash map is evil code.) 2) Is the hashMap.put(new Obj(), null) statement "replace"? That was my initial assumption, but I can't think of any English expressions or idioms containing "replace". – COTO Jul 28 '15 at 15:40
  • @COTO null is the value, the two new Obj instances are the keys, with separate identities, so the second won't replace the first. – Kevin Rubin Jul 28 '15 at 16:13
  • @Kevin: Because hashCode returns 1 for all instances of Obj, when used as a key, the values will replace each other in the HashMap. In this case, it replaces null with null. – Ian MacDonald Jul 28 '15 at 17:53
  • 3
    @IanMacDonald As I understand it, the hashCode is used for performance, to find the item in the HashMap's internal buckets, not to identify an individual key within those buckets. As a quick test I just pasted the code to an editor, printed the size of the map and after the second put there are two items in it. – Kevin Rubin Jul 28 '15 at 18:04
  • @Kevin I suppose it would also require equals to return true. But then I wonder what the point of including it at all was... – Ian MacDonald Jul 28 '15 at 18:11
  • 1
    @pacoverflow: I overlooked the fact that you hadn't overridden equals. So possibly "two in a bucket", "twice in the bucket", "toss in the bucket", then possibly "turns over", "around", "dumps out", "overturns", then possibly "block", "empty", "nothing", "empty-handed". And because it's a rebus, "over", "under", "with", etc. can always play a part. A-aaaand... I've still got nothing. :P – COTO Jul 28 '15 at 20:18
4

I think the answer is:

Love story

Reasoning:

hashSet.add(new Obj());

Here an object is being stored in a hash set [STORE]

e.rotate(Math.PI);

Here the object e is having a 180 degree rotation applied [E ABOUT]

{}

This is an empty block, so this code does nothing, or love as nothing can be termed in tennis for example [LOVE]

So putting it together we have:

STORE E ABOUT LOVE i.e. STORY ABOUT LOVE or LOVE STORY

Pete
  • 1,943
  • 13
  • 19
3

Is it

Much Ado About Nothing

Building quite heavily COTO's answer:

There's much code before the main(), but then it adds (sounds vaguely like "Ado") one more element, a new Obj object, to the collection, so it doesn't have none or one, but rather, much content.

The e.rotate(Math.PI) being "about".

And the empty code block {} being "Nothing".

Kevin Rubin
  • 205
  • 2
  • 6
0

I don't think this is what you're after, but it could look like part of one school of thought for the perfect barbecue:

add another one (second distinct Obj object: 'another', hashCode: 'one') to the block (static initialiser: 'block', also HashSet: reference to barbecue grids or the deliberate style of burn marks on the meat after cooking), turn it over once at the natural point, i.e. half way through cooking (e: base of natural logs, rotate by $\pi$: turn around), then just let it sit i.e. do nothing until it is done (empty brace = nop: do nothing , end of main(): 'done').

Lawrence
  • 7,919
  • 2
  • 22
  • 56