KBD

Keith Devens .com

Saturday, October 11, 2008 Flag waving
"You cannot want wrong things any more, now that you have died, my son," said Aslan. – C.S. Lewis (The Silver Chair, ch 16)
← Currying and partial applicationTime for me to learn Rails →

Daily link icon Thursday, August 25, 2005

When static typing gets in the way

I want to do the following in Java:

SuperClass s = Class.forName("fully-qualified-class").newInstance();
s.process(foo, bar);

I know that given what "fully-qualified-class" is I can call process on s, but Java's static typing thinks I can't, so it won't let me.

Update: I'd like to correct myself a little: Ultimately, the real reason that you can't call process on s is because on the base class the process method is protected, whereas on the subclasses I need to call it on it's public. So, you could argue that this is really a case where access controls (not static typing) are getting in the way, or a case where the access controls on this class hierarchy weren't designed well enough. I lumped this in with static typing because in a normal message-passing style of OO this wouldn't be an issue, since the message would be passed and the object would either accept or reject it.

← Currying and partial applicationTime for me to learn Rails →

Comments XML gif


Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

October 2008
SunMonTueWedThuFriSat
 1234
567891011
12131415161718
19202122232425
262728293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 7 posts

Recent comments XML

new⇒I hate PHP

Elliot Anderson,

Dude!! You the​man! The reverse replacement for​array_u...

Alex Ndungu: Oct 11, 1:35am

Call a function from a string in Python

?!code:
some_object.__getattribute​__('method_name')()
?!/code

is​the s...

Patrick Corcoran: Oct 8, 3:53pm

Spider solitaire

I have won 185 games of Spider​Solitaire at the "Difficult" level.​ What is...

75.179.28.113: Oct 8, 12:42pm

Sed one-liners

Hi.

I wanted to let you know​that I wrote an article "Famous Sed​One-Lin...

Peteris Krumins: Oct 8, 3:05am

Timesheet Calculator

Hadn't seen it before now, but my​company already uses a time​tracking prog...

Keith: Oct 7, 10:44am

Girls, please don't get breast implants

Hey everyone, 

I am new to this​blog and I have enjoyed reading all​your...

Sarah.M.: Oct 6, 9:45am

Generated in about 0.184s.

(Used 8 db queries)

mobile phone