Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java type system

 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim,

What you have explained about "A Real Problem" in the The Type System chapter of the book?

And are you talking about any possible improvement for the language in the book?

 
Jim Waldo
author
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you are talking about the real problem of the difference between the runtime type (which includes the classloader) and the compile time type (which does not).

If so, I'm afraid I don't have any fixes at the language level. If I had a time machine, we could go back and stop the decision of making the classloader part of the type, so that the compile time type and the runtime type were the same. But making that change now would break too much existing code, to say nothing of all of the "clever" uses of classloaders that peoples have invented. Most of these are disgusting hacks (my technical term), but some are also useful.

As a craftsperson/programmer, you can avoid a lot of the problem cases by declaring all of your arguments and return values as interfaces rather than classes. Since interfaces are not scoped by classloader, you don't run into the same problem. This is yet another reason to have all of your declarations done with interfaces. I know that there are some people who think that I'm an interface bigot, but only because the use of interfaces lets you avoid to many problems.

At this point in Java's life, it is very hard to fix problems by changing the language, since almost everything is depended upon by a large number of running programs and systems. But we can find idioms that keep the problems from getting worse. Not as good as a real fix, but better than nothing.
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this point in Java's life, it is very hard to fix problems by changing the language, since almost everything is depended upon by a large number of running programs and systems.

Agree.
But we can find idioms that keep the problems from getting worse. Not as good as a real fix, but better than nothing.

Or even new features to do things in a proper way than before without breaking the old code yet can be applied to new code...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic