小编Gar*_*ien的帖子

Java Enum作为Enum中的泛型类型

我正在尝试在抽象类中创建一个抽象方法,该方法将我自己的Enum作为参数.但我也希望Enum是通用的.

所以我这样声明:

public abstract <T extends Enum<T>> void test(Enum<T> command);
Run Code Online (Sandbox Code Playgroud)

在实现中,我已经知道了那个:

public enum PerspectiveCommands {
    PERSPECTIVE
}
Run Code Online (Sandbox Code Playgroud)

并且方法声明变为:

@Override
public <PerspectiveCommands extends Enum<PerspectiveCommands>> void test(Enum<PerspectiveCommands> command) {

}
Run Code Online (Sandbox Code Playgroud)

但如果我这样做:

@Override
public <PerspectiveCommands extends Enum<PerspectiveCommands>> void test(Enum<PerspectiveCommands> command) {
    if(command == PerspectiveCommands.PERSPECTIVE){
        //do something
    }
}
Run Code Online (Sandbox Code Playgroud)

我无权访问PerspectiveCommands.PERSPECTIVE错误:

cannot find symbol symbol: variable PERSPECTIVE   location: class Enum<PerspectiveCommands> where PerspectiveCommands is a type-variable: PerspectiveCommands extends Enum<PerspectiveCommands> declared in method <PerspectiveCommands>test(Enum<PerspectiveCommands>)
Run Code Online (Sandbox Code Playgroud)

我做了一个这样的解决方法:

public <T extends Enum<T>> byte[] executeCommand(Enum<T> command) throws Exception{
    return …
Run Code Online (Sandbox Code Playgroud)

java generics methods enums

25
推荐指数
3
解决办法
8万
查看次数

Sharepoint的CAML查询中的日期时间比较

我正在尝试从sharepoint列表中获取某些项目,具体取决于自定义列中的日期.

我已经建立了我与U2U CAML查询生成器,而这工作,但是当我把它放在我自己的代码在我的WebPart,它总是返回我的所有项目OD列表.

这是我的代码:

DateTime startDate = new DateTime(Int32.Parse(year), 1, 1);
            DateTime endDate = new DateTime(Int32.Parse(year), 12, 31);
            SPQuery q = new SPQuery();
            q.Query = "<Query><Where><And><Geq><FieldRef Name='Publicate Date' /><Value IncludeTimeValue='FALSE' Type='DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(startDate) + "</Value></Geq><Leq><FieldRef Name='Publicate_x0020_Date' /><Value IncludeTimeValue='FALSE' Type='DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(endDate) + "</Value></Leq></And></Where></Query>";

            SPListItemCollection allItem = library.GetItems(q);
Run Code Online (Sandbox Code Playgroud)

c# sharepoint web-parts caml

12
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

caml ×1

enums ×1

generics ×1

java ×1

methods ×1

sharepoint ×1

web-parts ×1