小编luc*_*uca的帖子

Java界面问题

假设我有2个接口,A和B:

public interface A {
 List<B> getBs();
}

public interface B {
}
Run Code Online (Sandbox Code Playgroud)

和2个实现这些接口的类:

public class AImpl implements A {

 public List<B> getBs() {
  return null;
 }

}


public class BImpl implements B {
}
Run Code Online (Sandbox Code Playgroud)

是否可能(可能使用泛型)我的getter方法返回BImpl类型对象的列表,如下所示:

public class AImpl implements A {

 public List<BImpl> getBs() {
  return null;
 }

}
Run Code Online (Sandbox Code Playgroud)

谢谢

java generics interface covariance

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

如何编写正则表达式只提取前面有某个字符串的数字?

我有一个字符串(包含JSON):

[{"type":[236]} , {"type":[2]} , {"type":[95]}, {"other":[33]}, {"other":[44]}]
Run Code Online (Sandbox Code Playgroud)

我想使用正则表达式只提取TYPE数字,以便输出是以下字符串:

[236 , 2 , 95]
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

java regex

0
推荐指数
2
解决办法
240
查看次数

标签 统计

java ×2

covariance ×1

generics ×1

interface ×1

regex ×1