That was my misunderstanding especially about subtyping of value types.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
Map<String, Integer> map = new TreeMap(); | |
map.put("abc", 123); | |
map.put("def", 456); | |
map.put("ghi", 789); | |
map.get("abc"); | |
map.get(123); // java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a.map { b in | |
b.map { c in { | |
foo(b, c) | |
} | |
} | |
for b in a { | |
for c in b { | |
foo(b, c) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
import static java.lang.System.out; | |
public class VarianceTest { | |
static class Animal { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Array2<T> { | |
var buffer: Buffer<T> | |
var count: Int | |
init() { | |
buffer = Buffer() | |
count = 0 | |
} | |
init(_ elements: T...) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol O { | |
func f() -> String | |
} | |
struct A : O { | |
func f() -> String { | |
return "a" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.koherent.appengine.test; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Set; | |
import java.util.TreeSet; | |
import javax.servlet.ServletException; |
NewerOlder