I have a class C(Of T). I want to determine if some given value has type C, regardless of what T is. For example, I might want to determine if a value is a strongly-typed list, regardless what type of items the list stores.
I just need to know how to do it in VB.net. In Java the syntax is like this:
var result = obj instanceof Gen2<?>;...
In Scala v 2.7.7
I have a file with
class Something[T] extends Other
object Something extends OtherConstructor[Something]
This throws the error:
class Something takes type parameters
object Something extends OtherConstructor[Something] {
However, I can't do this
object Something[T] extends OtherConstructor[Something[T]]
I...
I have a basic type system type mismatch problem:
I have a class with a method
def Create(nodeItem : NodeItem) = {p_nodeStart.addEndNode(nodeItem)}
where p_nodeStart is NodeCache
class NodeCache[END_T<:BaseNode] private(node: Node) extends BaseNode {
def addEndNode(endNode : END_T) = {this.CACHE_HAS_ENDNODES.Create(endNode)}
and th...
class TestClass[T](val x: T) {
def +(other: TestClass[T]) = x + other.x
}
this definition gives me the following compile error:
error: type mismatch;
found : T
required: String
def +(other: TestClass[T]) = x + other.x
is it not possible to use Int or Double as a type parameter and use addition in Scala??
...
List<T> Foo<T>(Ilist list)
where T : ??
is there any way to enforce T to be
one of few classes ?
eventually i want to do a switch on T..
thanks.
...
In what situations should abstract types be preferred over type parameters?
...
EDIT 2:
I managed to achieve the type safety I wanted in my exercise with RomanNumerals using a combination of mixins and type parameters with the code below. In essence what it does is after importing everything in RomanNumerals I am able to write L X V I, but not L L or X L X cause then I get a type mismatch compiler error (since tho...
I am wondering why the two type parameters (named "A") with the same name ("A") is allowed as per the example below. I know this is a POOR naming of type parameters, don't do this.
(My guess is that they are on a on a different scope level, e.g. class level and function level, and the compiler is using some kind of name mangling)
clas...
Hi,
I get the following error when trying to compile this:
Btree.scala:9: error: could not find implicit value for parameter ordering: Ordering[K]
abstract class Node[K,V] extends TreeMap[K,V]
TreeMap is supposed to accept an implicit Ordering[A] val which I provide. Perhaps the implicit parameter needs to be in object Tester ...