English 中文(简体)
计数阵列和计数型
原标题:Scala arrays and parameterized types

I m试图界定一个通用的等级,该等级为“参数”T,然后在“Array”定义中使用该类别。 我写了我认为应该做的以下文字:

class MyClass[T] {

  val myarr:Array[T] = new Array[T](10)

}

但汇编者抱怨如下:

  • can t find the class manifest for element type T
  • value newArray is not a member of Null

任何人都知道,这里会发生什么情况,以及它对什么不满意?

最佳回答

汇编者需要了解如何即时处理T类物品。 在传统的瓦 Java处理一般产品时,不能合理地这样做;汇编者刚才说,“我不知道什么T,因此,我对允许你即刻发出这样的T并不感到如此之大。 然而,在Schala,有一言之四。 为了列入T号清单,将该法典的第一行改为“T”。

class MyClass[T : Manifest] {

这就是说。

问题回答

暂无回答




相关问题
Having many stacks with different types

I m making a C program that needs to use two stacks. One needs to hold chars, the other needs to hold doubles. I have two structs, node and stack: struct node { double value; struct node *...

Creating (boxed) primitive instance when the class is known

I need a method that returns an instance of the supplied class type. Let s assume that the supplied types are limited to such that an "empty" instance of them can be created. For instance, supplying ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

How to generate an instance of an unknown type at runtime?

i ve got the following in C#: string typename = "System.Int32"; string value = "4"; theses two strings should be taken to generate an object of the specified type with the specified value... result ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

热门标签