JaroslavTulach at 15:31, 14 July 2016 - 2016-07-14 15:31:44

←Older revision Revision as of 15:31, 14 July 2016
Line 21: Line 21:
More info at [[Covariance]]. For possible trick around this behavior see [[Erasure]].
More info at [[Covariance]]. For possible trick around this behavior see [[Erasure]].
 +
 +
[[Category:APIDesignPatterns]]
 +
[[Category:APIDesignPatterns:Evolution]]

JaroslavTulach at 09:21, 13 December 2011 - 2011-12-13 09:21:45

←Older revision Revision as of 09:21, 13 December 2011
Line 7: Line 7:
<source lang="java" snippet="variance.contravariance.v2"/>
<source lang="java" snippet="variance.contravariance.v2"/>
-
Existing code would compile against the new library. However because the rules for looking up the right method are different between [[JavaC]] and [[JVM]] code like following will have problems:
+
Existing code would compile against the new library. However because the rules for looking up the right method are different between [[JavaC]] and [[JVM]], we'll have a problem. Code like this will compile fine, but...
<source lang="java" snippet="variance.contravariance.test"/>
<source lang="java" snippet="variance.contravariance.test"/>
-
If compiled against version 1.0 and executed against version 2.0, it will throw linkage errors:
+
...if compiled against version 1.0 and executed against version 2.0, it will throw linkage errors:
<source lang="bash">
<source lang="bash">

JaroslavTulach at 17:33, 19 October 2011 - 2011-10-19 17:33:35

←Older revision Revision as of 17:33, 19 October 2011
Line 1: Line 1:
-
Everything one would ever like to know about [[Covariance]] and [[Contravariance]] is available at [[wikipedia:Covariance_and_contravariance_(computer_science)|wikipedia]]. Here is just a small example how it does not work in [[Java]].
+
Everything one would ever like to know about [[Covariance]] and [[Contravariance]] is available at [[wikipedia:Covariance_and_contravariance_(computer_science)|wikipedia]]. Here is just a small example how it does not work in [[Java]] (the argumentation is the same as in case of [[Covariance]]). First version would like to be fixed:
-
[[TBD]]
+
<source lang="java" snippet="variance.contravariance.v1"/>
 +
 
 +
However when one tries to change the parameter type:
 +
 
 +
<source lang="java" snippet="variance.contravariance.v2"/>
 +
 
 +
Existing code would compile against the new library. However because the rules for looking up the right method are different between [[JavaC]] and [[JVM]] code like following will have problems:
 +
 
 +
<source lang="java" snippet="variance.contravariance.test"/>
 +
 
 +
If compiled against version 1.0 and executed against version 2.0, it will throw linkage errors:
 +
 
 +
<source lang="bash">
 +
Mixing should not work: Compiling with version 1.0 and running against version 2.0 fails.
 +
Exception in thread "main" java.lang.NoSuchMethodError: api.Contravariance.isPositive(Ljava/lang/Integer;)Z
 +
at test.ContravarianceTest.main(Unknown Source)
 +
Java Result: 1
 +
</source>
 +
 
 +
More info at [[Covariance]]. For possible trick around this behavior see [[Erasure]].

JaroslavTulach: New page: Everything one would ever like to know about Covariance and Contravariance is available at wikipedia. Here is just a ... - 2011-10-18 05:42:47

New page: Everything one would ever like to know about Covariance and Contravariance is available at wikipedia. Here is just a ...

New page

Everything one would ever like to know about [[Covariance]] and [[Contravariance]] is available at [[wikipedia:Covariance_and_contravariance_(computer_science)|wikipedia]]. Here is just a small example how it does not work in [[Java]].

[[TBD]]