小编Dan*_* R.的帖子

凝聚"超级"

我想写一个像这样的Interator:

class Plant { }
class Tree extends Plant { }
class Maple extends Tree { }

// Iterator class: compiler error on the word "super".
class MyIterator<T super Maple> implements Iterator<T> {
    private int index = 0;
    private List<Maple> list = // Get the list from an external source.

    public T next() {
         Maple maple = list.get(index++);
         // Do some processing.
         return maple;
    }

    // The other methods of Iterator are easy to implement.
}
Run Code Online (Sandbox Code Playgroud)

从概念上讲,这个想法是让迭代器看起来像返回树或植物(即使它们总是Maples),而不为每个迭代器编写单独的类.

但是当我通过时,编译器不喜欢它T super …

java generics

7
推荐指数
1
解决办法
175
查看次数

在 Postgres 中,索引是否会传递到视图中?

Postgres 表上的索引是否可以加快引用它的视图的搜索速度?

例如,假设我有以下内容:

CREATE TABLE my_table(my_column INT);  -- Then insert lots of rows into the table.
CREATE VIEW my_view AS SELECT my_column FROM my_table;
CREATE INDEX my_index ON my_table(my_column);
SELECT * FROM my_view WHERE my_column = 1;
Run Code Online (Sandbox Code Playgroud)

第 4 行的 SELECT 语句是否受益于第 3 行的索引?

database postgresql

7
推荐指数
1
解决办法
2002
查看次数

标签 统计

database ×1

generics ×1

java ×1

postgresql ×1