What the $heck?

Did you know the dollar sign ($) is a valid character in a Java variable name? Imagine my surprise when a student showed me the method he wrote. It’s supposed to calculate the amount of tip to leave at a restaurant table.

 * Given the dollar amount of the bill, return 15% tip.
public double tip(double $)
    return $ * 0.15;

I was so sure this was a bug in the IDE that I submitted a bug report. Then I read the Java spec on identifier names.


1 thought on “What the $heck?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s