[英]Instantiating a generic object that uses <Foo extends Bar<Foo>>
I am working on creating a B+Tree class using generics. 我正在使用泛型创建B + Tree类。 Here is the beginning of my class declaration and constructor: 这是我的类声明和构造函数的开始:
/**
* B+ Tree generic type
*
* @author Sofian Benaissa
*/
public class BplusTree<K extends Comparable<K>,V>
{
private static int maxKeys = 10;
private Node<K> root;
private Node<K> currentLeaf;
/**
* Default Constructor
*/
public BplusTree()
{
root = new Node<K>(null, 0);
currentLeaf = root;
}
I have created a gist with the complete source for this class here: https://gist.github.com/sfyn/7622365 我已经在此处创建了包含该课程完整源代码的要点: https : //gist.github.com/sfyn/7622365
Next I am trying to instantiate this class in another file. 接下来,我尝试在另一个文件中实例化此类。 This line: 这行:
private BplusTree<String><String>;
Followed by this line in a constructor: 在构造函数中紧接以下行:
bptree = new BplusTree<String><String>();
Throws these errors when compiled: 编译时引发以下错误:
src/FileParser.java:30: error: <identifier> expected
private BplusTree<String><String> bptree;
^
src/FileParser.java:30: error: <identifier> expected
private BplusTree<String><String> bptree;
^
src/FileParser.java:30: error: <identifier> expected
private BplusTree<String><String> bptree;
^
src/FileParser.java:39: error: '(' or '[' expected
bptree = new BplusTree<String><String>();
^
src/FileParser.java:39: error: illegal start of expression
bptree = new BplusTree<String><String>();
^
5 errors
The syntax 语法
private BplusTree<String><String> bptree;
is incorrect. 是不正确的。
The correct syntax is a comma separated list of type arguments 正确的语法是用逗号分隔的类型参数列表
private BplusTree<String, String> bptree = new BplusTree<String, String>(); /* or new BplusTree<>(); in Java 7 */
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.