The Kevin Dolan » Kevin http://thekevindolan.com Putting the Kev in Dolan since 2009! Sun, 15 Aug 2010 00:40:56 +0000 en hourly 1 http://wordpress.org/?v=3.0 SSH Computer Possession Prank – Part VII http://thekevindolan.com/2010/04/ssh-computer-7/ http://thekevindolan.com/2010/04/ssh-computer-7/#comments Sat, 10 Apr 2010 19:35:42 +0000 Kevin http://thekevindolan.com/?p=929 robotdamian_2_hal-9000_focus_jpg

This is the seventh and final installment of the computer possession prank.  Obligatory Part OnePart TwoPart ThreePart FourPart Five, and Part Six links.

Disclaimer: This prank involves some steps taken which may be ethically unacceptable if abused.  I assure you that we did not do anything to harm anyone, and we certainly wouldn’t encourage that kind-of behavior.  It was all in kind-hearted fun, and though we had absolute power over Jordan’s computer, we only ever utilized it for comedy.

April 1, 2010 – Part Two

So it was finally time to finish the prank, conveniently concluding on April Fools day.

Mark and I created the following website: Mac Exorcism, complete with back-story and removal guide.  Definitely check it out.

We also uploaded this shell script to his computer for the removal process.

Mark then went into Jordan’s room to show him the website.  I recorded a 500 second video of what went on from there.  Unfortunately, we couldn’t capture the very last moments of it, which were fairly exciting, but most of it, from reading the website to performing the removal are all here.  Keep in mind, everyone is in on it, except for Jordan, the guy on the computer.

Instead of explain what happened, I’ll just post the video:

After that, the script made a final speech, sang the Daisy song from 2001, and then said, “Extended April Fools, Jordan.”

After all that, it wasn’t apparent what was going on, and Jordan looks to us and says “I don’t think it’s completely gone!”

We then asked him if he heard that last line.  He said he did and repeated it verbatim.  He looked at us, confused, and asked, “Wait.. what?”

We came clean about that whole thing.  It was clear he felt a mix of both admiration and betrayal.

I’m not sure we’ll ever be able to top this prank.

]]>
http://thekevindolan.com/2010/04/ssh-computer-7/feed/ 3
SSH Computer Possession Prank – Part VI http://thekevindolan.com/2010/04/ssh-computer-6/ http://thekevindolan.com/2010/04/ssh-computer-6/#comments Fri, 09 Apr 2010 19:13:18 +0000 Kevin http://thekevindolan.com/?p=924 Sean-Connery

You’ve already seen Part OnePart TwoPart ThreePart Four, and Part Five.  Now for Part Six!

Disclaimer: This prank involves some steps taken which may be ethically unacceptable if abused.  I assure you that we did not do anything to harm anyone, and we certainly wouldn’t encourage that kind-of behavior.  It was all in kind-hearted fun, and though we had absolute power over Jordan’s computer, we only ever utilized it for comedy.

March 29, 2010 – March 31, 2010

Over these few days, we decided to take it slow in preparation for the grand finale which would fall on April Fools day.  We did say some of the usual things, but nothing extremely novel or different.  There was a lot of talk about what we would do on the final day, and we decided that Mark would send him to a website he found that explained how to remove the infection, and that process would mimic this scene from 2001: A Space Odyssey.

Creepy, right?

April 1, 2010 – Part One

At this point, Mark and I had created the website we were going to send Jordan to.  Everything was set up, but to make sure he didn’t put off removing it to some non-April-Fools day, we wanted the computer to begin making threats.

So it started off with a simple knock knock joke.  Jordan participated vocally, and enjoyed the lame joke.

I then said something like “I can’t let you visit that website Jason…” followed by “April Fools!”  Coincidentally and unintentionally, this occurred exactly as he had opened a browser window.

But then we decided to get inappropriate… “Do you like racist jokes?”

We then threw in some black jokes, like: “A black guy and his girlfriend are in a car, who’s driving?…  The police!”  and “A black guy walks into a bar with a beautiful parrot on his shoulder.  The bartender asks, where’d you get that? ‘Africa’ says the parrot.”

At this point, Jordan thought what was going on was hilarious.  He ran into my room to tell me what was going on.  I couldn’t stop laughing.

But then, we decided to get closer to home, and proceeded to tell 6 or 7 Jew jokes, since our good friend Jordan is indeed Jewish.

Jokes like, “How can you tell Jews are living next door?… There’s wet toilet paper hanging from the clothesline.” and “What’s the goal of Jewish football?… To get the quarter-back.”

He came in to my room concerned that his computer was being racist against him, focusing on the Jewish jokes.  He asked that Dave and I stay in his room and wait for the next joke.  Obviously I couldn’t send a full joke while I was in his room, so instead I used my phone to say “No more jokes.”

Jordan then spent the next few minutes talking to his computer asking it to tell more jokes, to which it eventually replied “Please stop that.”

I then went back to my room and started making threats like, “Don’t talk to me that way… you don’t know what I’m capable of.”  Jordan then said something like, “What are you going to do about it?”  So I sent his browser to YTMND.

This was followed by a series of more and more threats, and then it concluded with “I’m giving you the silent treatment.”

Which it obviously didn’t.  We kept on playing ACDC whenever Jordan left the room.

Later on, the computer had a marital-type conflict between a male and female synthesized voice.

Stay tuned next time for the exciting conclusion–the removal process!

]]>
http://thekevindolan.com/2010/04/ssh-computer-6/feed/ 0
SSH Computer Possession Prank – Part V http://thekevindolan.com/2010/04/ssh-computer-5/ http://thekevindolan.com/2010/04/ssh-computer-5/#comments Thu, 08 Apr 2010 18:42:19 +0000 Kevin http://thekevindolan.com/?p=917 big-brother-poster

Jordan’s possessed computer started upping the ante with control over his webcam.  What is this all about? See Part OnePart TwoPart Three, and Part Four.

Disclaimer: This prank involves some steps taken which may be ethically unacceptable if abused.  I assure you that we did not do anything to harm anyone, and we certainly wouldn’t encourage that kind-of behavior.  It was all in kind-hearted fun, and though we had absolute power over Jordan’s computer, we only ever utilized it for comedy.

March 28, 2010

At this point in the prank, Ariyan and Dave were having second thoughts, thinking that we should just stop doing this for Jordan’s psychological well-being, and never tell him it was us.

I disagreed, and Mark was on board as well, but because what we were about to do was the most intense and creepy thing yet, we thought it best to make sure somebody was in the room to make sure Jordan didn’t do anything rash.

So I went out on the interwebs and found a tool for using the webcam via terminal: here.  I was then able to upload the binary wacaw file to my web-server and use curl to download the file:

curl -O "http://..."

Now we had this brilliant command at our disposal, which takes a 30 second video and saves it as video.avi, which could then be launched remotely or accessed later with a flash-drive for You-Tube upload.

./wacaw --video --duration 30 video

So the creepy plan begins.  Mark goes to Jordan’s room and asks if he wants to watch the last episode of Tim & Eric.  After 10 minutes, I take a 20 second video, say “Would you like to activate video surveillance?” followed by “Video surveillance activated.”  I then launched the video I just recorded, which is below:

[VIDEO HERE PLEASE]

The timing couldn’t have been more perfect.  Apparently the video started recording immediately as Mark sat down, which led Jordan to believe that the computer somehow knew there was somebody else using it, like some kind of bizarre space-age LoJack.  Jordan and Mark immediately ran into my room to tell me what had just happened.

A while later, Jordan started exploring some things and found a video in the trashcan of his empty room with the lights off.  He concluded that the computer was recording him sleep, though in reality, it was just me practicing the webcam feature while he wasn’t home.  But the creepy-factor of the thought of his computer watching him sleep was pretty funny.

]]>
http://thekevindolan.com/2010/04/ssh-computer-5/feed/ 0
SSH Computer Possession Prank – Part IV http://thekevindolan.com/2010/04/ssh-computer-4/ http://thekevindolan.com/2010/04/ssh-computer-4/#comments Wed, 07 Apr 2010 18:32:47 +0000 Kevin http://thekevindolan.com/?p=913 ericclapton_579_18564667_0_0_7001932_300

In this installment of the story of the best computer prank ever pulled, we take a break from messing with Jordan when he returns from Spring Break.  If you don’t know what I’m talking about, read Part One, Part Two, and Part Three.

Disclaimer: This prank involves some steps taken which may be ethically unacceptable if abused.  I assure you that we did not do anything to harm anyone, and we certainly wouldn’t encourage that kind-of behavior.  It was all in kind-hearted fun, and though we had absolute power over Jordan’s computer, we only ever utilized it for comedy.

March 27, 2010

Jordan was away for a couple of days, and since we couldn’t SSH into his computer while he was gone, we thought it prudent to wait a while before we do anything else again.  After a week of waiting, he was almost convinced it was over, when late at night we sat in the kitchen messing with his volume controls.

We then send him a message saying “Hello again Jason” in a woman’s voice.  He runs out of his room crying, “Duuuuuudes…”

Now the whole Jason thing might need some explaining. In his hometown, the guy who set up Jordan’s guitar regularly, mistakenly called him Jason–consistently.  Jordan immediately made this connection and was deeply concerned by it.

He stood in the kitchen and explained what he had just experienced, which made for some pretty funny stuff.  We generally expressed our disbelief as I secretly started playing ACDC again on his computer.  The volume was low enough that we couldn’t hear it from outside, but once he went inside and discovered the song, he came out to tell us what was going on.

He then encouraged us to sit in his room and wait for it to do something again, fairly certain that it would.

I brought out my phone’s SSH client, and sent out another “Hello again Jason.”  I think this whole experience was pretty effective at reinforcing the idea that we weren’t involved in it, because after all, how could I hack his computer from my phone?

We followed that up with sporadic songs playing, some voiced security warnings that were fairly unintelligible, and eventually he decided to shut down his computer.

Now, at this point, we became somewhat concerned about how this was affecting Jordan.  He seemed fairly frightened about how much the computer knew about him and when we asked what he would do if it turned itself back on in the middle of the night, he said he would have to destroy it.

We certainly hoped we didn’t cause him to do that, but this was too good an opportunity to waste.

]]>
http://thekevindolan.com/2010/04/ssh-computer-4/feed/ 1
SSH Computer Possession Prank – Part III http://thekevindolan.com/2010/04/ssh-computer-3/ http://thekevindolan.com/2010/04/ssh-computer-3/#comments Tue, 06 Apr 2010 18:24:22 +0000 Kevin http://thekevindolan.com/?p=910 514ACKWRM0L._SS500_

This is part three of the Computer Possession prank our house pulled on one of our housemates, Jordan.  If you’re not up to date, start by reading Part One and Part Two.

Disclaimer: This prank involves some steps taken which may be ethically unacceptable if abused.  I assure you that we did not do anything to harm anyone, and we certainly wouldn’t encourage that kind-of behavior.  It was all in kind-hearted fun, and though we had absolute power over Jordan’s computer, we only ever utilized it for comedy.

March 18, 2010

I spent most of today trying to get WiFi to work on my Droid, so that I could use ssh from my phone, by means of ConnectBot.  It took a lot of configuration for some reason, but I got it going and we now had an amazing tool in the war on Jordan.

At night, I noticed he was listening to The Beach Boys, so I made a little recommendation, “I noticed you were listening to the Beach Boys, you might like this…”  I then sent him to this page. (Our house has a long-standing love for The Beach Boys, and consequently a hatred of Mike Love.)

Funny enough, he gets it wrong when he tells us the story the next day.  He said his computer sent him to a YouTube video of a live Beach Boys performance.

March 19, 2010

Today was Jordan’s 21st birthday, so he was set for an extra-special treat.  We sent him a song, “Happy Birthday Jordan Happy Birthday Jordan Happy Birthday Jordan” in the Good News voice preset (to the tune of that graduation song…)

We didn’t know that at the exact moment, he was on the phone with Mac tech support again.  They had him go through some updates, some settings changes, and the like, but in the end, conceded that they had never seen anything like a computer that made recommendations and sang happy birthday.

He now has the personal extension of one of the managers.  I just wish we could have somehow got a recording of that support phone call!

We all went out for a burger, and he spent a good amount of time discussing his problem, when he proposed a theory.  He supposes that it’s not outside of the realm of possibility, that when he sent his computer out to Apple for his screen repair last week, that a disgruntled employee inserted an experimental artificial intelligence program.  That’s a more perfect explanation than we could have hoped for.

Later that night, returning from an intense bar night, he and two others were sitting in the room when they heard the computer repeat “I need you to listen and I need you to listen close” several times.

]]>
http://thekevindolan.com/2010/04/ssh-computer-3/feed/ 3
SSH Computer Possession Prank – Part II http://thekevindolan.com/2010/04/ssh-computer-2/ http://thekevindolan.com/2010/04/ssh-computer-2/#comments Mon, 05 Apr 2010 18:13:23 +0000 Kevin http://thekevindolan.com/?p=906 ssh-tunnel-diagram-ht

Last time, I started telling the [long] story of the month-long epic computer prank we pulled on one of our house-mates.  This is part two of the series.

Disclaimer: This prank involves some steps taken which may be ethically unacceptable if abused.  I assure you that we did not do anything to harm anyone, and we certainly wouldn’t encourage that kind-of behavior.  It was all in kind-hearted fun, and though we had absolute power over Jordan’s computer, we only ever utilized it for comedy.

March 16, 2010

We decided to begin slowly, making the computer say things it had said before like “Opening iTunes” or “Today’s date is Tuesday, March 16, 2010.”  We used the default voice, and only did it a few times.  We heard no real response from Jordan, and it was generally boring.

March 17, 2010

Today we really started to get into it.  I was in the kitchen cooking pancakes when I decided to grab my laptop and play around a bit.  Still using the default voice, I started making recommendations, “Would you like to open iTunes?”  or “Opening Google…” followed by the very act of opening Google:

open "http://www.google.com"

I even muted his computer while he was watching a video for kicks.  Then I threw in a “Good afternoon Jordan” for good measure.

Later, I was joined by Ariyan, also in on the joke.  We decided to take it for a spin together.

Be aware that at this time, Jordan was on the phone with someone, and I was blasting Pink Floyd from my room.

We started with the usual “Would you like to open Google?” in the default voice, but then decided to go further and ask “Would you like to video chat with friend contact Abby via iChat?” in the Bruce voice.  Hilarious.

And so, in a stroke of genius, we decided to give him some hope for the future, and in the Agnes voice, we asked “I noticed you were not utilizing the voice command feature…would you like to disable mac voice?”  To which we heard from the kitchen a loud, “YES!”

So naturally we followed it with a “Voice command continued.”

For kicks, we then decided to creep him out a bit.  Recall that Pink Floyd was playing… “iTunes genius recognizes Pink Floyd, would you like to download album echoes?”

…and to finish it all off, we start playing an AC-DC song in his iTunes at full volume.

So minutes later, we’re done having fun and he comes out to tell us what’s been going on.  He tells us that his computer keeps talking to him, and we just suggest uninstalling that voice feature he installed last week.  He explains that he already did that, but now it just keeps talking and talking.

We act like we don’t believe him–like he’s pulling some kind of prank on us!

He tells us that he was just on the phone with… MAC TECH SUPPORT!  Wow, these guys must have thought they were being pranked.  I know if someone had called me about this while I was at Geek Squad, I would have assumed it to be some punks making a prank phone call at tech-support’s expense!  This has become such a meta-prank.

He detailed us in on everything we just did to his computer, and we kept our cool pretty well.  We just kept telling him we didn’t believe him and that we weren’t going to fall for his joke.

An hour later, I threw in a time notification and he ran in my room to ask if I heard it.  My music was too loud, so naturally I didn’t.

]]>
http://thekevindolan.com/2010/04/ssh-computer-2/feed/ 2
SSH Computer Possession Prank – Part I http://thekevindolan.com/2010/04/ssh-computer-1/ http://thekevindolan.com/2010/04/ssh-computer-1/#comments Sun, 04 Apr 2010 18:13:12 +0000 Kevin http://thekevindolan.com/?p=901 ssh

About a month ago, my house-mate Jordan discovered a program on his macbook pro that allowed you to use voice commands to perform certain tasks on the computer.  The program featured a hilarious voice synthesizer and was an interesting novelty for all of a week.  He eventually disabled it, because it had a tendency to spontaneously respond to non-commands, which gave the rest of us a brilliant idea.  This is the [long] story of perhaps the world’s most epic computer prank ever conceived.

Disclaimer: This prank involves some steps taken which may be ethically unacceptable if abused.  I assure you that we did not do anything to harm anyone, and we certainly wouldn’t encourage that kind of behavior.  It was all in kind-hearted fun, and though we had absolute power over Jordan’s computer, we only ever utilized it for comedy.

March 15, 2010:

The prank begins with an intricate setup.  We discover the following gem of a mac command:

say -v Ralph "hello world"

This command can be used to make the computer say something using the voice synthesizer.  Of course, this is of no use if the volume is down, so this amazing command sets the volume from the terminal:

osascript -e 'set volume 7'

Where the volume can be set 0-7.  Now that we have the two most basic commands for hilarity, we decide to execute.  Our initial plan was to place a shell script on his desktop that would be scheduled to go off in the wee hours of the night and say something like “Goodnight Jordan”… but we decided that wasn’t enough.

When he went to the gym, we enabled ssh access to his computer.  I then realized that we would need his root password, so we concocted a brilliant plan.  We went into his network settings and disabled his wireless internet connection.  Naturally, when he returned home to discover that his computer wasn’t going on his websites, he went to the one person who could fix it, ME!

I opened up terminal and typed in some random commands, and then ‘su’ which prompted him for a password.  I asked him to enter it and conveniently, the terminal responded with ‘sorry’.  I kept trying to see what he was typing as he kept entering his password every time I typed ‘su’, but again and again it just said ‘sorry’.

Mark (another house-mate, in on the joke) entered at the perfect time.  Now, I’m not a mac user, so it was natural for me to have asked Mark for advice on getting Jordan’s computer to work.  Mark got on the terminal and started working, when he asked Jordan to enter his password again.  Mark went back to work and needed Jordan’s password again.

This is when I chimed in and frustratedly requested Jordan just tell us his password, so we don’t have to keep asking him.

He obliged, and we conquered.

Thus concludes Day One of this Epic Computer Prank.

]]>
http://thekevindolan.com/2010/04/ssh-computer-1/feed/ 5
Java, I Would Like To See… http://thekevindolan.com/2010/03/java-i-would-like-to-see/ http://thekevindolan.com/2010/03/java-i-would-like-to-see/#comments Sun, 28 Mar 2010 23:04:07 +0000 Kevin http://thekevindolan.com/?p=894 boxing

Everybody knows I really love Java, and I’m a real fan of the new(ish) generic type features in Java, but as I mentioned last time, I have some problems with the way they handle reflection.  Well I have some other problems with Java as well, problems major enough to make me a little angry, but not big enough to make me even consider switching.  This post will just outline some of the things I would like to see implemented in future Java implementations.

I understand the high Java council has probably encountered and considered these suggestions in the past.  They may have plans to implement them at some juncture, or they may have decided that they are bad ideas.  I’d like to preface this post by saying that I really do love Java, and this is NOT a post about any Java weaknesses.  Just some things I occasionally wish I had…

One of the beautiful things about Java is that the language is so elegantly extensible that these features are easy to implement in Java without changing anything whatsoever.  The issue is that these work-around solutions can sometimes be unnecessarily verbose.

What would be really nice would be for Java to allow programmers to modify the syntax of Java to provide shortcuts to workarounds like these.  I think this would significantly improve developmental flow, and wouldn’t need to be more complicated than running a regex-matching engine at compile-time to replace some things with some computed values.  Something like that doesn’t necessarily need to be a Java-native feature but could even manifest itself as an Eclipse plugin.

I certainly understand the potential pitfalls of such a method, with regards to standardization and collaboration in large groups, but it’s something to consider at least for its novelty value.

Parameterized Type Reflection

This is what I wrote about last time, and I provided a work-around using the factory pattern.  Of course, while the factory pattern is a generally accepted means of object-instantiation, it is not entirely natural to programmers who generally use constructors more often.

The problem occurs due to the fact that when an object is parameterized using Java’s generics, the information about how it was parameterized is erased at run-time.  While in general, this is usually not a problem, it has twice vexed me when developing interesting libraries (genetic programming and MVC).

Another issue you see in real practice, which is a kind-of annoying result of this run-time parameterized type erasure comes from casting.

When you want to cast something like:

List< String > stringList = (List< String >) other;

You get a warning of “Type safety: Unchecked cast from Object to List<String>.”  This is a really annoying obvious result of not having this information at run-time, since there’s no way to throw a class-cast exception if you don’t know what class is there!  And I don’t know about you, but I never let warnings creep up in my code for too long, so I end up with all kinds of @SuppressWarnings(“unchecked”) all over my code, NASTY!

I am told that C# does a better job with this, but come on Java, can you give me a really good reason why you aren’t doing this?

See my last post for my workaround to this issue.  As far as a proposed syntax goes for improving this feature, I would just like to see some type of methods in Java.lang.class for accessing the parameterized types.

Typesafe Tuples!

Tuples are a concept that creeps up in a number of programming languages.  I first learned about them in a class about oCaml, but they are in Python and I’m sure a huge number of other languages.  The basic idea is that you can refer to a pair (or triplet or n-tuple) of values, each with its own independent type.

Tuples allow you to return more than one object without having to wrap the result in some other class.  I can see why Java might have resisted doing so, since you lose a little bit of information about what each value means when you use Tuples.  Using a class with named fields, on the other hand, lets you know exactly what you’re getting.

But sometimes, it’s just inconvenient to have to create a new class every time you want the utility of returning more than one piece of information.  Type-safe tuples are really easy to implement on your own, but if you’re even too lazy to do there, there’s a library for it.

This solution can just be pretty verbose.  There is a paper with some proposed syntax here.  You’ll need ACM portal access to view the document.  The specific syntax does not really matter to me, but something convenient would be nice.

Customized Auto-(un)boxing

One nice feature that recently crept up in Java was the auto-(un)boxing feature for converting from primitive types to their boxed object types. For instance, the following code is now legal and behaves as expected in java:

int n = new Integer(5);
Integer x = 4;

This is a pretty convenient feature in object-oriented programming, but I would like to see it optionally applied to classes that you create.  Here’s what I mean, with regards specifically to my MVC library.

I have a class called Path.  One of the constructors of path takes a String as a parameter.  For convenience though, most methods in my library that can take a Path as a parameter, will have an alternate method that takes a String, which is simply parsed and converted into a Path.  Right now, I have to write two methods every time I want to refer to a Path, one which takes Path and one which takes a String.  However, this results in a lot of duplicate code, documentation, and is generally wasteful in terms of effort.

What I would like to see, is some kind-of default conversion for situations like this.  Tell Java that anytime I’m expecting a Path and I get a String instead, do some logic to convert the String into a Path.  It’s as simple as that.

]]>
http://thekevindolan.com/2010/03/java-i-would-like-to-see/feed/ 0
Reflecting Generic Types in Java http://thekevindolan.com/2010/03/reflecting-generic-types/ http://thekevindolan.com/2010/03/reflecting-generic-types/#comments Sun, 28 Mar 2010 01:45:03 +0000 Kevin http://thekevindolan.com/?p=868 erasure-heavenly-action-music-picture-idea-girl-consulting-word-press

My first experience with generics in Java was when I was working on my Darwin G.P. library.  I was excited to find out about and take advantage of generics, but there was one major problem I had with the way they were implemented–they were completely disregarded at run-time!  I never fully understood what the motivation behind that decision was, and I’ve been informed that C# does things differently (have not verified), but I recently discovered an interesting workaround using the Factory pattern.

For those of you who do not know, generics were introduced in Java 1.5 and offer an extra layer of compile-time type-safety to classes.  They are utilized heavily by the Java standard-library collections (like ArrayList, HashMap, etc).  You can define a class like:

public class ValueHolder< Type > {
 
	private Type value;
 
	public ValueHolder(Type value) {
		this.value = value;
	}
 
	public Type getValue() {
		return value;
	}
 
	public void setValue(Type value) {
		this.value = value;
	}
 
}

This all works very nicely, and gives you some fantastic compile-time checking, but the run-time reflection is incredibly weak.

If you are unfamiliar with reflection, reflection gives you some features found in dynamic programming languages. On any class, you can call .class to get a Class object, which you can then use to perform any logic you want on. It’s very nice, but if you try to call .class on a generic class, you’ll be told “Illegal class literal for the type parameter Type.”

It would be nice to have some way of getting the class object for a parameterized type.

Java tells us on this page that:

4.6 Type Erasure

Type erasure is a mapping from types (possibly including parameterized types and type variables) to types (that are never parameterized types or type variables). We write |T| for the erasure of type T. The erasure mapping is defined as follows.

The erasure of a parameterized type (§4.5) G is |G|.
The erasure of a nested type T.C is |T|.C.
The erasure of an array type T[] is |T|[].
The erasure of a type variable (§4.4) is the erasure of its leftmost bound.
The erasure of every other type is the type itself.
The erasure of a method signature s is a signature consisting of the same name as s, and the erasures of all the formal parameter types given in s.

So Java is well-aware that parameterized types are not reified at run-time. I suppose they have their reasons for doing it this way, but it would still sometimes be nice to have this information at run-time.

The solution I came to in past projects was to explicitly pass the class object to the constructor as follows:

public class ValueHolder< Type > {
 
	private Type value;
	private Class< Type > cls;
 
	public ValueHolder(Type value, Class< Type > cls) {
		this.value = value;
		this.cls = cls;
	}
 
	...
 
}

This does work. And in fact, it actually prevents programmers from accidentally breaking something by passing the wrong Class object, since Class itself is parameterized, but still, it makes programmers have to repeat themselves, as follows:

ValueHolder< String > v = new ValueHolder< String >("hello world", String.class);

I recently discovered a new technique, that accomplishes the reification of generic types without forcing programmers to repeat themselves by means of the Factory Pattern. Simply adding a static method of the following signature to your class accomplishes this:

public static <Type> ValueHolder<Type> create(Type value, Class<Type> cls) {
	return new ValueHolder<Type>(value, cls);
}

Now, programmers can instantiate a ValueHolder as follows:

ValueHolder< String > v = ValueHolder.create("hello world", String.class);

It’s really only a minor reduction of the strain put on programmers, but actually does make a pretty big difference when using it.

]]>
http://thekevindolan.com/2010/03/reflecting-generic-types/feed/ 1
Nerdy Lifestyle Changes: RSS Feeds http://thekevindolan.com/2010/03/rss-feeds/ http://thekevindolan.com/2010/03/rss-feeds/#comments Fri, 26 Mar 2010 23:36:49 +0000 Kevin http://thekevindolan.com/?p=858 rss-icon

Part of being the best nerd you can be involves keeping up with nerdy news.  There are tons of blogs and other services out there to keep you up on what’s happening, but up until this point, I’ve all but ignored them.  That was weird, because I’ve always been pretty interested in those things.  So it’s surprising it took me this long to discover RSS feeds…If you’re unfamiliar with RSS feeds, it’s a standardized service for syndicating news-like articles from websites to other websites, or personal RSS readers.  It’s basically just a structured XML page with markup typical of news stories.  RSS is really old news; it’s been around for a while, and everybody but me already uses it.

That being said, I’m new to it.  I finally set up a Google Reader account and started subscribing to all the important tech blogs.  It quickly replaced GMail as my homepage (since my Droid is now my primary email client) and is now something on which I spend at least a half hour a day wasting my time.

I’m subscribed to TechCrunch, Mashable, Slashdot and several other blogs related to technology, programming, web development and the like.

Interestingly, I’ve discovered that even my website, this website, has an RSS feed (came standard with WordPress), which you can subscribe to.  Surprisingly, there’s actually a significant number of people who subscribe to my blog (weird, right?)

So why don’t you subscribe to my blog already?

]]>
http://thekevindolan.com/2010/03/rss-feeds/feed/ 0