开发者

JSR 303 Validation - Ensure field is of specific interface implementation

I'm looking for something which is probably out there, hence why I'm asking and not just creating it...

Let's say I have the following:

public interface SillyInterface {
    public String name(开发者_运维百科);
}

public class SillyInterfaceImplA {
    public String name() {
        return "SillyImplA";
    }
}

public class SillyInterfaceImplB {
    public String name() {
         return "SillyImplB";
    }
}

Now let's assume I have the following POJO:

public class SillyPOJO {
    SillyInterface silly1;
    SillyInterface silly2;
}

Is there any annotation (Hibernate or stock) which exists, such that I can ensure that I get a reference to a certain concrete implementation (without changing my POJO to make silly1 a reference type to the one I wish)?


Hibernate has the best validation support for JSR 303, and you can view all of the annotations here:

http://docs.jboss.org/hibernate/validator/4.2/reference/en-US/html_single/#d0e332

You can even write custom annotations for your own validation routines, although that is a lot of work for what you're trying to do. Unfortunately, like "matt b" said, this only gives you runtime support, even if you wrote something custom.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜