Enum type param in Java

I ran into an interesting Java generics issue when writing my solution to HW1 for CSE 546 this past weekend. I wanted to make a generic ID3Tree class so that I could test my decision tree with different inputs (i.e. the examples in the book) easily. I wanted to make the tree’s classification type the generic type parameter for the class, and since I was only dealing with discrete types, I wanted to make a class that accepted any enum as a type parameter. All Java enums are classes that extend Enum, so I initially just wrote a header like this:

public class ID3Tree<E extends Enum<E>> { ...

I then attempted to use E.values() and E.valueOf(), but got compiler errors. Apparently, these methods are not inherited from Enum (they don’t exist in Enum at all) but they are added by the compiler when the compiler translates the enum into a public final class.

My initial thought was, no problem, I’ll just add a wrapper interface that I’ll make the enums implement that have values() and valueOf(). Except wait, you can’t put static methods in an interface. And I can’t make the enums extend a class with the necessary methods because a) single inheritance (they already extend Enum) and b) even if I could extend a second class, static methods are hidden, not overridden when defined in subclasses.

So my workaround was to still make a wrapper interface Classifier<E extends Enum<E>> with instance methods for values() and valueOf(), then make the ID3Tree constructor take a Classifier object parameter.

Code skeleton below… kind of gross. But thought I’d post in case someone else ran into a similar problem. If there is some cleaner workaround, let me know! Kevin suggested Reflection, which I always forget about. Other ideas?

public class ID3Tree<E extends Enum<E>> {
    private Classifier<E> classifier;
    public ID3Tree(Classifier<E> c, ...)
        classifier = c;
        ...
    }
}

public interface Classifier<E extends Enum<E>> {
    public E[] values();
    public E valueOf(String name);
}

EDIT: Kevin for the save! Check out this awesome alternative solution:

public class Foo<E extends Enum> {
    private E[] values;
    public Foo(Class cls) {
        this.values = cls.getEnumConstants();
    }
}

I love the description for getEnumConstants(). This method was sooo clearly added as an afterthought, lol :thumbup:

Why women are not in computer science, and why psychologists are useless

There’s been some talk and discussion going around the CS department about an article published last month, which discovers that gee, the nerdy “coder boy recluse” stereotype is unattractive to women, and it suggests that this may be a primary reason why women are not pursuing computer science.

The Daily published an interesting follow-up article today featuring responses from our department chair and a few lovely CSE undergrads, saying basically that, a) no kidding and b) our CSE building is nothing like the stereotypical environment and still we have problems overcoming the stereotype.

I agree with everything they’ve said, but I have a much more negative response to the study: the “Star Trek” stereotype is not even close to core of the problem with recruiting women in CSE, and it’s incredibly insulting to treat it as such.

I mean, really? You really think that UW undergrad women on the whole are petty enough to dismiss a fulfilling, lucrative career choice because we think the surroundings won’t be pretty and comfortable enough? Because we get the “feeling that we don’t fit in” here, that the department is full of gross smelly boys so we aren’t willing to get over it?

Not only is this insulting, but it goes against everything I’ve observed about pettiness in this area. If we’re going to talk purely on a superficial level, then I would say most women (and men, for that matter) LOVE defying the stereotype. There’s a certain glamor to it; many young CS undergrads relish in being different and looking pretty and clean and untouchable to their nerdier, socially inept counterparts. More often than not I see women receiving a boost in confidence (or ego, depending on your cynicism) after joining the department because — to be frank to the point of controversy — even if they might be considered only “average” in looks, social skills, etc. in most other settings, average is in some ways above and beyond the expected for CSE.

Of course, I remind you that this is talking purely on a superficial level. Which is purely the level on which this study makes claims.

What’s hilarious to me is that the lead author of the study, Sapna Cheryan, notes that the math department has about 50% female math majors and asks, “Why are [women] 50 percent of math majors and only 20 percent of computer science?”

Well, right. There are 50% women math majors, and math has a “geek stereotype” so prevalent that it’s cliche. You can’t cite this statistic and say, “whoa see, computer science is weird” then point to a characteristic that is apparent in both math and computer science (i.e. girls think the field contains nerds) as a reason why computer science is lacking in women.

So what is the problem? Why do we have a shortage of women in computer science? I don’t have the answers to this, but I have a lot of speculation. And it’s a difficult problem, not one that can be solved by introducing more gender-friendly posters into a computer lab.

I think image is certainly a problem, but not the coke cans and scifi posters. One image problem is that people don’t know what computer science is, and one of the huge reasons for this is our K-12 system. From my understanding, computer science education in K-12 is a mess. Many schools don’t offer any CS courses, and many of the schools that do offer CS have terrible curriculum then teach their terrible curriculum terribly. If we could show our students in grade schools and high schools that computer science is a fun, engaging, and creative pursuit, we would increase our enrollment of women and men at the college level, guaranteed. There are some heroes working to make this happen, but it’s a really, really difficult problem whenever you try to fix the bureaucratic mess that is K-12 in America.

Another issue — this one perhaps more traditionally associated with women — is confidence in technical skills and intimidation by those who live permanently on their linux terminal. There is a HUGE problem with women thinking they are “not good enough” to be in this major. I taught CSE 142 over the summer, and a female student who got a 3.8 in the course (mean grade was 2.74, median 3.0) was telling me how she was really worried about the next course and unsure of whether to continue.

Even when girls are in the major, there are just anecdotes after anecdotes after anecdotes of women who have better transcripts and resumes than their male counterparts, but have the perception that they everyone else knows so much more than them. Because of this they don’t bother seeking out internships (or get discouraged quickly if one company rejects them), then because they don’t have internships they don’t get the on-the-job skills, then by the time they graduate they no longer have resumes on the same competitive level as maybe some of the males do.

I could go on and on. There are certainly problems with female interest in computer science, and certainly a large part of this is a problem with perception. But it’s not “environment, environment, environment”, and it disgusts me that one can actually get funding to conduct and publish studies based on such shallow and unoriginal hypotheses.

Judy Garland: always the right decision

I think Judy Garland is becoming to my 20s as Mariah Carey was to my childhood. (i.e. a holy divinity)

Read the rest of this entry »

If you don’t know computers…

…PLEASE DO NOT MAKE STRONG OPINIONS ABOUT COMPUTERS!!

Today I overheard so many acts of computing ignorance, it was a little bit alarming. In none of these situations was it appropriate for me to interject with my opinion, so instead I shall passive aggressively vent via blog:

  • Instance 1 (from a tester): “Developers always write their programs in Firefox, then complain that they don’t work in IE6! But that’s their fault for using Firefox. They should just program to make it work in IE6, because if it works for IE it usually works for everything.
  • Instance 2 (from a person who “knew Java”):I picked up a C# book to see what it was like, and it is nothing like Java. I don’t know why anyone says they’re similar.”
  • Instance 3 (from a person who was “okay at C++”): “Object-oriented languages are too unnecessarily complicated. That’s why I like C++: no classes or pointers.

It was so hard for me not to be like, “PARDON ME SIR I BELIEVE YOU ARE INCORRECT” but decided against it considering I was not actively a part of any of these conversations. UGH but Instance 3!! Honestly, above all else, if you say you like C++, you’re doing it wrong. (Or you’re a C++ wiseman who’s doing it very very right… but clearly this guy was not.)

AHHHHH

I FORGOT TO REHASH ON INSERT WHEN THE HASH TABLE IS FULL/REACHED LOAD FACTOR. NOOOOOOOOOOOOOOOOOOOOO

But the interviewer said he saw my blog prior to interview, so I will post this here *just in case* he sees it. I’m sorry Mr. Interviewer, I totally meant to rehash but I forgot while staring at the whiteboard. Then remembered approximately 6 hours later when I was at home doing the dishes.

/interview drama of the day

This will not end well

So I just found out about Amazon PayPhrase today (a couple weeks late, I know). The premise is, you can choose a secret phrase and a secret pin, and if you know these two things then you can shop “securely” without having to enter your credit card.

But they’re SUGGESTING their own randomly generated pay phrases for you? And these randomly generated pay phrases are relatively predictable in nature? And the pin is only 4 digit numbers? And the 4-digit numbers people choose are quite likely going to be easily guessable numbers, like last 4 digits of phone number?

This confuses me. It feels like these “pay phrases” are just username/password, except with longer user names and with 1990s-style super-uniform, super-guessable, super-insecure passwords. Unless there is something going on that I am missing, this makes me make a concerned face ala Tim Gunn.

Also, the suggested payphrases seem to be eerily relevant to your interests:
payphrase_screenshot

Tempting as it may be, I don’t think I will claim this (or any) pay phrase…

Gold Peak Green Tea

Gold Peak Green Tea

I wanted a cold green tea for my lunch today, so I bought Gold Peak Green Tea at By George. It is by far the WORST SWEETENED TEA I HAVE EVER TASTED. It’s got this sickeningly, syrup-like sweetness with only the faintest aftertaste of tea. I could barely stomach more than a few sips before I poured it down the drain.

But another way to think about it is, I was so thirsty during lunch, but after a small gulp of this, I totally lost all thirst – for the wrong reasons of course, but still! Does that make it an effective drink?

You know it has been a while since you last did laundry if. . .

  1. You’re about to start your laundry and for a few seconds you don’t remember which knobs to turn anymore.
  2. After washing your first load laundry and uou are putting the next load in the dryer, you see on a t-shirt some suspicious looking color blotches that you don’t recall seeing before.
  3. When you’re about to start your second load, you realize you forgot one crucial step in the washing process the first time around: setting the laundry temperature.

Oh, it’s good to be a college student. (I can’t believe I’ll be graduating so soon–!)

Aretha is an untouchable goddess

Aretha Franklin - I Never Loved a Man the Way I Love You

I hate that most people only associate Aretha Franklin with her pop songs. Her pop sound is fantastic, but they’re so overplayed that they sound cliche; it cheapens the songs and makes it hard for people to appreciate them.

So if you’ve never heard an Aretha song outside of Respect and Chain of Fools, take this opportunity to educate yourself:

A Change is Gonna Come – Aretha Franklin

Dr. Feelgood – Aretha Franklin

This album is SO GOOD! I love you Aretha!!! :girlhappy:

Stuff to make your life better

Here’s another installment of recent successful purchases! (And another reminder that I am a girl and I like girl things.)

Strawberry milk
Strawberry Milk
Have you had strawberry milk lately? I have been an avid supporter of chocolate milk, and since I was little I’ve preferred it to any other type of flavored milk. But then–! The other day I tried buying strawberry milk on a whim (the strawberry milk pictured above in fact) and it was so delicious! I was pleasantly surprised and now I think I am addicted.
Read the rest of this entry »