March 22, 2006

Blog has been moved

This post has been moved to blogspot. No further posts will be made to this location.

Java Quiz

Bonus points to anyone who knows what the results of this will be without running it or looking at the documentation. ;-)
    public void testTrue() {
        String str = "true";
        boolean expected = true;

        assertEquals("not what you expected?", expected, Boolean
            .getBoolean(str));
    }

    public void testFalse() {
        String str = "false";
        boolean expected = false;

        assertEquals("not what you expected?", expected, Boolean
            .getBoolean(str));
    }
For anyone interested, here's the documentation. Posted by jim at March 22, 2006 05:36 PM
Comments

isn't reading the documentation cheating? After reading the documentation does anybody else think this function is in the wrong spot?

Posted by: Kibbee at March 22, 2006 08:03 PM

I agree... and I think that the name sucks wrt what it actually does... It would be good if they just made another method that does that same thing and depreciate getBoolean().

Posted by: Jim at March 22, 2006 10:12 PM

You could probably just deprecate this function, and use Boolean.parseBoolean(System.getProperty(str)).
I don't really see that you'd need to use this function all that often, and even if you did, then the solution I mentioned would be much more clear to other programmers as to what you were actually trying to accomplish.

Posted by: Kibbee at March 23, 2006 08:33 AM
Due to the proliferation of comment spam, I’ve had to close comments on this entry. If you would like to leave comment, please use one of my recent entries. Thank you and sorry for any inconvience caused.