Java static binding for parameters and covariance/contravariance

Lujop <lujoplujop@gmail.com>
19 Nov 2004 00:53:07 -0500

          From comp.compilers

Related articles
Java static binding for parameters and covariance/contravariance lujoplujop@gmail.com (Lujop) (2004-11-19)
Re: Java static binding for parameters and covariance/contravariance newsserver_mails@bodden.de (Eric Bodden) (2004-11-20)
Re: Java static binding for parameters and covariance/contravariance vbdis@aol.com (2004-11-20)
Re: Java static binding for parameters and covariance/contravariance mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2004-11-20)
Re: Java static binding for parameters and covariance/contravariance lujoplujop@gmail.com (Lujop) (2004-11-26)
Re: Java static binding for parameters and covariance/contravariance vbdis@aol.com (2004-11-26)
Re: Java static binding for parameters and covariance/contravariance boldyrev+nospam@cgitftp.uiggm.nsc.ru (Ivan Boldyrev) (2004-11-28)
| List of all articles for this month |

From: Lujop <lujoplujop@gmail.com>
Newsgroups: comp.compilers
Date: 19 Nov 2004 00:53:07 -0500
Organization: Compilers Central
Keywords: Java, question
Posted-Date: 19 Nov 2004 00:53:06 EST

Hi,


I don't know if this is a little offtopic because is more a language
question, but like languages and compilers are related to... Well,
it's nice to have a moderator to decide this ;)


I'm writing a compiler for a pseudocode language that also has to work
as a translator to Java code. Then I am limited to Java features
(extensions like multijava can't be applied)


Please excuse me if I don't use the correct terms, I'm not an expert
in object oriented langauges. And also my english isn't very good.


Java uses static binding for parameters. And only uses overriding when
the signature of the method is the same (This is the invariant way,
isn't it?).


I think that the best way is to be able to use dynamic binding for
parameters like (MultiJava extension) allows. But I can't do this
because the restriction to generate Java code.


Then my problem is that I thinked to use a contravariant way for
parameters in my language. And don't allow to "overwrite" the method
m(A) in class B with method m(B) where B<=A.
And only allow to override parameters methods in a contravariant way.


I think that this is less powerful, but it's more clear than Java and
less error prone. Because in java when you "override" m(A) whith m(B),
you are overloading (not overriding) and I think that is very confuse,
and isn't very util, and very error prone. In fact Effective Java from
one of Java library architects has a norm that says that you don't have
do it.


Then, my question is. What do you think that's better? What Java
does, or what I proposed? Can you give my some readings about it? Are
my terms correct (refering to covariance,contravariance and
invariance?)


A lot of thanks in advance,


PD1: I think that the better way is the covariant way like multijava
allows, but I can't use it.
PD2: My language is for didactic purpouses. Then as less error prone as
it can be better.


--
Lujop


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.