Y*G
2 楼
假定我自己定义了一个qualifier: Year用来描述汽车制造的年份
@Qualifier
public @interface Year {
int value();
}
如果我需要2010年生产的汽车,我可以用
...
@Autowired
@Year(2010)
private Car car;
...
我怎么可以表达“我要2010年以后生产的汽车”?
下面的写法不工作:
...
@Autowired
@Year(value>2010)
private Car car;
...
@Qualifier
public @interface Year {
int value();
}
如果我需要2010年生产的汽车,我可以用
...
@Autowired
@Year(2010)
private Car car;
...
我怎么可以表达“我要2010年以后生产的汽车”?
下面的写法不工作:
...
@Autowired
@Year(value>2010)
private Car car;
...
s*l
3 楼
从去年6月开始到现在只拿到一个onsite(自我感觉是陪跑),基本没有什么消息,工
作出来的本来就少,要求又高,学到化学Phd了,怎么一点价值和认同感都感觉不到?
不知道自己还能干什么了。。。。家里的那位是我师兄,这一家可怎么办啊。。。。
作出来的本来就少,要求又高,学到化学Phd了,怎么一点价值和认同感都感觉不到?
不知道自己还能干什么了。。。。家里的那位是我师兄,这一家可怎么办啊。。。。
Y*y
4 楼
嗯,短,但是剧情流畅简洁,非常棒。
Y*G
5 楼
我的前提条件是容器的配置是正确的,2010以后的汽车只有一辆,不会没有。autowire
不会出现问题。
不会出现问题。
z*e
7 楼
等下,spring允许你自己写annotation了?
你用spring的话,应该用不到@interface吧?
你用spring的话,应该用不到@interface吧?
o*e
9 楼
跟spring有毛关系
l*3
10 楼
找码公试试。会计算机打字的都年薪10w
o*e
13 楼
要实现lz的想法办法有几个。没那么复杂,lz想多了。
这跟spring真没关系。lz你的year interface只有一个int 变量,你给“value>2010”
这个进去,算啥?必须是int才行啊。
你这个写法,就不是java了,是人类语言了。lol。
直接写多一个annotation最简单,
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.beans.factory.annotation.Qualifier;
@Target({ElementType.FIELD,ElementType.PARAMETER,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface NewerThanYearTwoOTen{
}
@NewerThanYearTwoOTen
@Year(2018)
public class NewBMWBENZshittyCar implements Car{
...
}
@Autowired
@NewerThanYearTwoOTen
private Car car;
简单粗暴。bingo, you get a NewBMWBENZshittyCar.
或者用你的办法,就得这样。跟spring没关系了。
if (obj.isAnnotationPresent(year.class)) {
Annotation annotation = obj.getAnnotation(Year.class);
Year year = (Year) annotation;
if(year.value > 2010){
//do whatever you want here;
}
}
这跟spring真没关系。lz你的year interface只有一个int 变量,你给“value>2010”
这个进去,算啥?必须是int才行啊。
你这个写法,就不是java了,是人类语言了。lol。
直接写多一个annotation最简单,
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.beans.factory.annotation.Qualifier;
@Target({ElementType.FIELD,ElementType.PARAMETER,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface NewerThanYearTwoOTen{
}
@NewerThanYearTwoOTen
@Year(2018)
public class NewBMWBENZshittyCar implements Car{
...
}
@Autowired
@NewerThanYearTwoOTen
private Car car;
简单粗暴。bingo, you get a NewBMWBENZshittyCar.
或者用你的办法,就得这样。跟spring没关系了。
if (obj.isAnnotationPresent(year.class)) {
Annotation annotation = obj.getAnnotation(Year.class);
Year year = (Year) annotation;
if(year.value > 2010){
//do whatever you want here;
}
}
L*u
14 楼
chemistry is dead?
o*e
15 楼
马来个鸡蛋,我是不是闲的很蛋痛?nnd。全看pornhub算了。
d*i
17 楼
楼主明显想多了,这个用annotation显然是overkill了,而且由于用了reflection而使
得性能下降。最简单粗暴的就是把year放到Car里面, 这样既符合面向对象的基本原则
,又不会因为滥用annotation和反射而导致性能下降:
public class Car {
private int year;
public boolean isGreaterThanGivenYear(int given) {
return year > given ? true : false;
}
//other methods.....
}
得性能下降。最简单粗暴的就是把year放到Car里面, 这样既符合面向对象的基本原则
,又不会因为滥用annotation和反射而导致性能下降:
public class Car {
private int year;
public boolean isGreaterThanGivenYear(int given) {
return year > given ? true : false;
}
//other methods.....
}
Y*G
19 楼
把Year放到Car里面去,那怎么用autowired呢?
Y*G
21 楼
假定我自己定义了一个qualifier: Year用来描述汽车制造的年份
@Qualifier
public @interface Year {
int value();
}
如果我需要2010年生产的汽车,我可以用
...
@Autowired
@Year(2010)
private Car car;
...
我怎么可以表达“我要2010年以后生产的汽车”?
下面的写法不工作:
...
@Autowired
@Year(value>2010)
private Car car;
...
@Qualifier
public @interface Year {
int value();
}
如果我需要2010年生产的汽车,我可以用
...
@Autowired
@Year(2010)
private Car car;
...
我怎么可以表达“我要2010年以后生产的汽车”?
下面的写法不工作:
...
@Autowired
@Year(value>2010)
private Car car;
...
Y*G
22 楼
我的前提条件是容器的配置是正确的,2010以后的汽车只有一辆,不会没有。autowire
不会出现问题。
不会出现问题。
z*e
23 楼
等下,spring允许你自己写annotation了?
你用spring的话,应该用不到@interface吧?
你用spring的话,应该用不到@interface吧?
o*e
24 楼
跟spring有毛关系
o*e
26 楼
要实现lz的想法办法有几个。没那么复杂,lz想多了。
这跟spring真没关系。lz你的year interface只有一个int 变量,你给“value>2010”
这个进去,算啥?必须是int才行啊。
你这个写法,就不是java了,是人类语言了。lol。
直接写多一个annotation最简单,
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.beans.factory.annotation.Qualifier;
@Target({ElementType.FIELD,ElementType.PARAMETER,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface NewerThanYearTwoOTen{
}
@NewerThanYearTwoOTen
@Year(2018)
public class NewBMWBENZshittyCar implements Car{
...
}
@Autowired
@NewerThanYearTwoOTen
private Car car;
简单粗暴。bingo, you get a NewBMWBENZshittyCar.
或者用你的办法,就得这样。跟spring没关系了。
if (obj.isAnnotationPresent(year.class)) {
Annotation annotation = obj.getAnnotation(Year.class);
Year year = (Year) annotation;
if(year.value > 2010){
//do whatever you want here;
}
}
这跟spring真没关系。lz你的year interface只有一个int 变量,你给“value>2010”
这个进去,算啥?必须是int才行啊。
你这个写法,就不是java了,是人类语言了。lol。
直接写多一个annotation最简单,
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.beans.factory.annotation.Qualifier;
@Target({ElementType.FIELD,ElementType.PARAMETER,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface NewerThanYearTwoOTen{
}
@NewerThanYearTwoOTen
@Year(2018)
public class NewBMWBENZshittyCar implements Car{
...
}
@Autowired
@NewerThanYearTwoOTen
private Car car;
简单粗暴。bingo, you get a NewBMWBENZshittyCar.
或者用你的办法,就得这样。跟spring没关系了。
if (obj.isAnnotationPresent(year.class)) {
Annotation annotation = obj.getAnnotation(Year.class);
Year year = (Year) annotation;
if(year.value > 2010){
//do whatever you want here;
}
}
o*e
27 楼
马来个鸡蛋,我是不是闲的很蛋痛?nnd。全看pornhub算了。
d*i
28 楼
楼主明显想多了,这个用annotation显然是overkill了,而且由于用了reflection而使
得性能下降。最简单粗暴的就是把year放到Car里面, 这样既符合面向对象的基本原则
,又不会因为滥用annotation和反射而导致性能下降:
public class Car {
private int year;
public boolean isGreaterThanGivenYear(int given) {
return year > given ? true : false;
}
//other methods.....
}
得性能下降。最简单粗暴的就是把year放到Car里面, 这样既符合面向对象的基本原则
,又不会因为滥用annotation和反射而导致性能下降:
public class Car {
private int year;
public boolean isGreaterThanGivenYear(int given) {
return year > given ? true : false;
}
//other methods.....
}
Y*G
29 楼
把Year放到Car里面去,那怎么用autowired呢?
h*8
30 楼
ben mo dao zhi
相关阅读
Paper help! ThanksPaper Help(Synthetic Communications, 31(3), 375-379; 2001 )为尤它化学孤老默哀求助:推荐米国有机方面比较nice的牛老板海外给孙爱武的捐款途径 (转载)paper helppaper help![合集] 如何用TEM 表征 水溶液中胶束的形貌 (转载)[合集] RSC最近推出好多新杂志啊[THAA] Tsinghua Alumni Networking Dinner during MRS Meeting (转载)Paper help! Thanks化学男能成为老宋吗?zt 中国学术界的海龟与土鳖之争Paper help! Urgent !Thanks a lot!版上有做bioanalytical MS quantitation的同学么?will they accept my paper?Paper help!日常生活中容易买到的酸和碱化学公司如何在美国打广告和找代理调查:博后最希望在博后工作期间得到什么?