我的问题是关于Java 7中的泛型.假设我们有这样的类层次结构:
interface Animal {}
class Lion implements Animal {}
class Butterfly implements Animal {}
Run Code Online (Sandbox Code Playgroud)
我们还有一堂课
class Cage<T> {
private List<T> arr = new ArrayList<>();
public void add(T t) {
arr.add(t);
}
public T get() {
return arr.get(0);
}
}
Run Code Online (Sandbox Code Playgroud)
以下是使用该类的代码:
public static void main(String[] args) {
Cage<? extends Animal> cage = new Cage<>();
Animal a = cage.get(); //OK
cage.add(new Lion()); //Compile-time error
cage.add(new Butterfly()); //Compile-time error
}
Run Code Online (Sandbox Code Playgroud)
问题#1:
我在这里已经阅读过这些问题,但简直就是这样Cage<?>.但我告诉编译器<? extends …
我想处理按键组合(CTRL+ ENTER).
我试过这样做......
if ((event.getCharCode() == KeyCodes.KEY_ENTER)
&& event.isControlKeyDown()) {
//do smth...
}
Run Code Online (Sandbox Code Playgroud)
......但它不起作用.我也试图看到这个组合的代码,它显示10.所以我可能会这样做,event.getCharCode() == 10但我认为这不是很好的做法,特别是因为在API isControlKeyDown()和其他方面有这样的方法.捕获组合键的适当方法是什么?
我有2个属性文件a.properties和b.properties 我已经将应用程序上下文添加为:
<context:property-placeholder location="classpath:a.properties" />
<context:property-placeholder location="classpath:b.properties"/>
Run Code Online (Sandbox Code Playgroud)
具有属性的第一个文件包含数据库连接详细信息(这很有效)第二个 - 包含某些特定bean使用的属性.在那个bean中,我通过@Value注释使用这些属性
@Value("#{qw.er}")
private String someA;
@Value("#{as.df}")
private String someB;
Run Code Online (Sandbox Code Playgroud)
但是我在启动时遇到异常:
org.springframework.expression.spel.SpelEvaluationException:
EL1008E:(pos 0): Field or property 'qw' cannot be found on object of type
'org.springframework.beans.factory.config.BeanExpressionContext'
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
你有可能context:property-placeholder在一个文件中使用2 吗?
PS:属性qw.er和as.df仅存在于文件b.properties中
我想禁止解析a.b. 我想param从另一个配置替换。像这样:
val d = ConfigFactory.load(ConfigFactory.parseString(
"""
|param = x
|a.b = ${param}
""".stripMargin))
val a = ConfigFactory.parseString("param = 1")
val result = a.withFallback(d).resolve()
Run Code Online (Sandbox Code Playgroud)
在这种情况下,param获取值 1,但a.b仍然是x
我ConfigResolveOptions.defaults().setAllowUnresolved(true)在加载 config 时尝试设置的d,但这不起作用。
我怎样才能克服这个问题?
我有这样的代码:
DECLARE
e_not_exist EXCEPTION;
PRAGMA EXCEPTION_INIT(e_not_exist, -942);
car_name VARCHAR2(20);
BEGIN
select name_of_factory into car_name from car where car_id = 1;
dbms_output.put_line(car_name);
EXCEPTION
when e_not_exist then
dbms_output.put_line('Table or view does not exist');
when OTHERS then
dbms_output.put_line(to_char(SQLCODE));
END;
Run Code Online (Sandbox Code Playgroud)
实际上,我的表名是CARS但不是CAR.但oracle不处理此异常并给我一个错误ORA-00942:表或视图不存在.我该如何处理这个异常?
如果我的类将是一个不可变的类,它必须是final没有任何修改其状态的方法,并且所有属性必须是私有的.但为什么它应该声明为final(例如private final int a)?
编辑
如果类具有对不可变的对象的引用,那么该类仍然是不可变的吗?
假设我们有一个表格,其中包含有关人的信息.像NAME或SURNAME这样的列很小(我的意思是它们的大小不是很大),但是包含照片或者某个人的视频(blob列)的列可能非常大.所以当我们执行select操作时:
select * from person
Run Code Online (Sandbox Code Playgroud)
它将检索所有这些信息.但在大多数情况下,我们只需要检索人的姓名或姓氏,因此我们执行此查询:
select name, surname from person
Run Code Online (Sandbox Code Playgroud)
问题:Oracle会读取整个记录(包括blob列),然后只是过滤掉名称和姓氏列,还是只读取名称和姓氏列?
此外,即使我们为这样的大数据(人的照片和视频)创建了一个单独的表,并且在该人的表中拥有该表的外键并且只想检索照片,因此我们执行此查询:
select photo
from person p
join largePesonData d on p.largeDataID = d.largeDataID
where p.id = 1
Run Code Online (Sandbox Code Playgroud)
Oracle会在largePesonData中读取整个人员表和整个记录的记录,还是只读取largePesonData中带有照片的列?
在哪里可以找到Oracle如何在最低级别与数据库进行通信的信息,我的意思是在套接字级别?我想写一个程序(没有jdbc)只是执行一些语句(选择或创建).所以我需要知道Oracle使用什么协议来做到这一点.
如果没有对其中一个键的活动引用,我如何模拟WeakHashMap中条目的删除.我有下一个代码:
WeakHashMap<Integer, String> weakMap = new WeakHashMap<Integer, String>();
Integer st1 = 5;
Integer st2 = 6;
String val = "BB";
weakMap.put(st1, "AA");
weakMap.put(st2, val);
st1 = 10;
//st1 = null;
//System.gc();
for (Map.Entry<Integer, String> entry : map.entrySet()) {
System.out.println(entry.getKey() + " " + entry.getValue());
}
Run Code Online (Sandbox Code Playgroud)
总是输出
6 BB
5 AA
Run Code Online (Sandbox Code Playgroud)
但我希望只得到6 BB
即使我对注释行进行解除,它仍会产生相同的输出.据我所知,如果密钥在WeakHashMap其他地方之外weakHashMap的其他地方没有活动引用,则必须删除具有指定密钥的条目.我对吗?如果没有,请提出正确的解决方案.
我尝试使用版本2.0.0的shapless镜头scala 2.10.3我有类似于这个的代码:
import shapeless._
case class A(map: Map[String, String])
case class B(a: A)
val mapLens = lens[B] >> 'a >> 'map
Run Code Online (Sandbox Code Playgroud)
理念中的感染类型mapLens是
AnyRef with Lens[B, Nothing] {val gen: LabelledGeneric.Aux[Nothing, ::[record.FieldType[Witness.Lt[Symbol]#T, Nothing], Nothing]]}
Run Code Online (Sandbox Code Playgroud)
所以如果我想改变B实例的值
mapLens.set(b)(b.a.map + ("foo" -> "bar"))
Run Code Online (Sandbox Code Playgroud)
我收到类型不匹配错误.如何解决这个问题?
PS 这里有一个使用无定形镜片的例子.这lens[Person].address.street是怎么回事?我的意思是编译器如何允许我们在lense类的实例上调用case类的方法?因为在LenseExamples对象中使用了>>运算符
编辑 已在REPL中尝试过并且有效.Idea说它
could not find implicit value for evidence parameter of type shapeless.LabelledGeneric[B]{type Repr = Out0}
Run Code Online (Sandbox Code Playgroud)
同样的抱怨发出了争吵