标签: annotations

覆盖annotaion和JDK 1.5

我正在使用JDK 1.5,这是我的班级:

public final class Account implements ICAccount

{
//...
   @Override
   public ObjectID getId()
   {
      return new ObjectID(id);
   }
//...
}
Run Code Online (Sandbox Code Playgroud)

Account覆盖方法getId()ICAccount

但编译失败了.

Account.java  method does not override a method from its superclass  
Run Code Online (Sandbox Code Playgroud)

如果我正在使用JDK 1.6,则编译成功.

在@Override注释的文档中,我看到了

Since:
1.5  
Run Code Online (Sandbox Code Playgroud)

问题是什么?

java overriding annotations

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

使用iPOJO注释自定义Felix命令

我目前正在尝试使用iPOJO为Felix实现自定义shell命令.我的示例实现如下:

import java.io.PrintStream;

import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.shell.Command;

@Component(immediate = true)
@Provides
public class SampleCommand implements Command {


    @Override
    public String getName() {
        return "testcmd";
    }

    @Override
    public String getUsage() {
        return "testcmd";
    }

    @Override
    public String getShortDescription() {
        return "test command";
    }

    @Override
    public void execute(String line, PrintStream out, PrintStream err) {
        out.println("execute testcmd!");
    }

}
Run Code Online (Sandbox Code Playgroud)

当我在Felix上部署Bundle时,我的SampleCommand被实例化并且getName()被调用.但是当我尝试在shell上执行"testcmd"时,我得到:

gogo: CommandNotFoundException: Command not found: testcmd
Run Code Online (Sandbox Code Playgroud)

还有什么需要考虑的问题吗?

osgi annotations apache-felix

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

无法选择注释?

我在地图视图上有一个注释.我可以通过编程方式选择它,但我点击它没有任何反应.你可以帮帮我吗?有没有人遇到类似的问题?这是设置anotations的方法:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    MKAnnotationView *aView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MapVC"];
    if (!aView) {
        aView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MapVC"];
        aView.canShowCallout = YES;
        aView.draggable=YES;
        aView.leftCalloutAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
        // could put a rightCalloutAccessoryView here
    }
    aView.annotation = annotation;
    [(UIImageView *)aView.leftCalloutAccessoryView setImage:nil];
    return aView;
}
Run Code Online (Sandbox Code Playgroud)

并将它们添加到地图视图中:

- (void)updateMapView
{
    if (self.mapView.annotations) [self.mapView removeAnnotations:self.mapView.annotations];
    if (self.annotation) [self.mapView addAnnotation:self.annotation];
}
Run Code Online (Sandbox Code Playgroud)

并且对按下注释做出反应:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)aView
{
    NSLog(@"did select annotation");
}
Run Code Online (Sandbox Code Playgroud)

顺便说一句,方法[self.mapView selectAnnotation:annotation]有效,但没有提出一个标注(我用断点检查它).虽然只是录制注释不会(再次通过断点).

select annotations objective-c ios android-mapview

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

C#属性或属性

我知道你可以像这样在C#中为方法添加一个属性,

EX1.

[HttpPost]
public void Method()
{
//code
}
Run Code Online (Sandbox Code Playgroud)

这意味着必须满足该属性才能运行Method().

我知道你可以堆叠这样的属性,

EX2.

[HttpPost]
[RequireHttps]
public void Method2()
{
 //More code
}
Run Code Online (Sandbox Code Playgroud)

在您可以使用之前检查是否满足attribute1'AND'attribute2 Method2().

但你能'或'属性吗?这样的事可能吗?

EX3.

[HttpPost || RequireHttps]
public void Method3()
{
  //Even more code
}
Run Code Online (Sandbox Code Playgroud)

因此,如果满足任一属性,您可以使用Method3().

编辑:对不起,印象属于名为Annotations的属性.修正了.

c# attributes annotations custom-attributes asp.net-mvc-3

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

字段上的Java注释数量是否有限制?

字段上的Java注释数量是否有限制?我找不到关于这一点的任何信息.

java annotations

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

使用spring进行Java注释扫描

我有几个类需要用名称注释,所以我将我的注释定义为

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface JsonUnmarshallable {
    public String value();
}
Run Code Online (Sandbox Code Playgroud)

现在需要此注释的类被定义为

@JsonUnmarshallable("myClass")
public class MyClassInfo {
<few properties>
}
Run Code Online (Sandbox Code Playgroud)

我使用下面的代码来扫描注释

private <T> Map<String, T> scanForAnnotation(Class<JsonUnmarshallable> annotationType) {
    GenericApplicationContext applicationContext = new GenericApplicationContext();
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(applicationContext, false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(annotationType));
    scanner.scan("my");
    applicationContext.refresh();
    return (Map<String, T>) applicationContext.getBeansWithAnnotation(annotationType);
}
Run Code Online (Sandbox Code Playgroud)

问题是返回的映射包含["myClassInfo" -> object of MyClassInfo]但我需要映射包含"myClass"为键,这是Annotation的值而不是bean名称.

有办法做到这一点吗?

java spring annotations applicationcontext

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

没有注释的jackson过滤器属性

public Class User {
    private String name;
    private Integer age;
    ...
}

ObjectMapper om = new ObjectMapper();
om.writeValueAsString(user);
Run Code Online (Sandbox Code Playgroud)

如何在不使用@JsonIgnore等任何注释的情况下过滤属性?

java json annotations jackson

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

iOS 5自定义注释未显示其标题

我编写了这段代码来创建自定义注释图像

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    static NSString *google = @"googlePin";
    if ([annotation isKindOfClass:[myClass class]])
    {
        MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:google];
        if (!annotationView)
        {
            annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:google];
            annotationView.image = [UIImage imageNamed:@"pin.png"];
        }
        return annotationView;
    }
    return nil;

}
Run Code Online (Sandbox Code Playgroud)

图像出现在地图上; 但是当我点击它时没有任何事情发生,没有标题或副标题.

你们有什么想法吗?

annotations objective-c ios

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

在Groovy中使用JUnit @Before方法排序

我习惯于JUnit在子类中的@Before方法之前在超类中运行@Before方法.但是,我有一个继承自另一个Groovy类的Groovy测试类,它们都包含@Before方法; 我遇到的问题是测试类中的@Before方法在其超类中的方法之前运行,并且我从未初始化的变量获得NPE(超类应该处理它).

超类是这样的:

import groovyx.net.http.RESTClient
import org.junit.Before

abstract class BaseTestClass {
    def client

    @Before
    void setUp() {
        client = new RESTClient()
    }
}
Run Code Online (Sandbox Code Playgroud)

子类是这样的:

import org.junit.Before

class TestClass extends BaseTestClass {

    @Before
    void setUp() {
        client.post(path: '/entity', body: '{"id":"test"}')
    }

    ...
}
Run Code Online (Sandbox Code Playgroud)

这是一个简化版本,但是我得到了错误:java.lang.NullPointerException: Cannot invoke method post() on null object在子类的setUp()方法中.什么可能导致这种行为?所有的文档都说它应该是反过来的,我以前从未经历过任何不同的事情.

我正在使用maven-failsafe-plugin,junit-4.10和jdk-1.6.0_31运行.有趣的是,我有其他Groovy测试类在同一个地方(相同的包,相同的项目,相同的目录)没有遇到这个问题 - @Before方法的顺序是正确的; 此外,它似乎是确定性的 - 它始终是具有问题的相同测试类.

谢谢!

groovy junit annotations

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

java函数描述如何在eclipse代码建议中起作用

当我们使用eclipse时,它会为我们的java代码提供建议并显示描述,即显示有关该函数的描述的小型弹出窗口.假设我正在创建一个java库,我需要添加关于我的库中应该被eclipse识别并显示为建议的函数的这些描述,我应该如何指定描述,即我需要使用哪种类型或格式的注释来显示这些关于功能的描述.任何人都可以为我提供解决上述问题的链接.

java eclipse annotations javadoc

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