我有以下课程.
我已经使用javac手动编译了类并运行了Driver
该类.
后来删除了entity.class
和MyCustomException.class
运行应用程序,如下所示.
java驱动程序测试
以下错误被抱怨MyCustomException
丢失但不是关于Entity
班级.所以,不清楚为什么JRE抱怨MyCustomException
课而不是Entity
课.
确实我已经删除了代码,throw new MyCustomException();
但我没有遇到关于Entity
类的错误.
Caused by: java.lang.NoClassDefFoundError: com/techdisqus/exception/MyCustomException
Run Code Online (Sandbox Code Playgroud)
请注意,IF条件不会被执行,因为我将命令参数作为测试传递
为什么抛出异常会导致加载MyCustomException
永远不会执行的异常,但除非条件满足,否则JVM不会加载任何其他常规类,如此处的Entity
类所示.请检查Driver.java
下面.
MyCustomException.java
public class MyCustomException extends RuntimeException {
}
Run Code Online (Sandbox Code Playgroud)
Entity.java
public class Entity {
}
Run Code Online (Sandbox Code Playgroud)
Driver.java
public class Driver {
public static void main(String[] args) {
String s = args[0];
if("true".equals(s)){ …
Run Code Online (Sandbox Code Playgroud) 如何Supplier
使用lambda表达式替换此处的代码
IntStream inStream = Stream.generate(new Supplier<Integer>() {
int x= 1;
@Override
public Integer get() {
return x++ ;
}
}).limit(10).mapToInt(t -> t.intValue());
inStream.forEach(System.out::println);
Run Code Online (Sandbox Code Playgroud)
上面代码的输出是:
1
2
3
4
5
6
7
8
9
10
Run Code Online (Sandbox Code Playgroud) 我想了解如何Subscriber
和Publisher
在工作的java 9.
这里我在subscriber
这里创建了一个并SubmissionPublisher
用于发布项目.
我正在尝试发布100个字符串subscriber
.如果我不编写Client
程序sleep
(请参阅注释代码MyReactiveApp
),我看不到所有项目都已发布.
为什么不等待这里处理的所有字符串:
strs.stream().forEach(i -> publisher.submit(i)); // what happens here?
Run Code Online (Sandbox Code Playgroud)
如果我用上面的代码替换,我看到所有字符串都在控制台中打印
strs.stream().forEach(System.out::println);
Run Code Online (Sandbox Code Playgroud)
使用发布的客户端程序SubmissionPublisher
.
import java.util.List;
import java.util.concurrent.SubmissionPublisher;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class MyReactiveApp {
public static void main(String args[]) throws InterruptedException {
SubmissionPublisher<String> publisher = new SubmissionPublisher<>();
MySubscriber subs = new MySubscriber();
publisher.subscribe(subs);
List<String> strs = getStrs();
System.out.println("Publishing Items to Subscriber");
strs.stream().forEach(i -> …
Run Code Online (Sandbox Code Playgroud) 我试图以这样的方式解决数组中的配对数字(a,b)a*2 >=b
.其中a和b是来自输入数组的数字.
例子:
输入: a[] = {1,2,3,4,5}
输出:2
说明:
输入: a[] = {4,3,2,1,5}
输出:2
说明:
输入: a[] = {4,3,2,1,5,6}
输出:3
说明:
我尝试使用如下所示的递归来解决问题,但这并没有给出任何正确的结果.任何帮助,将不胜感激.
add 1
结果重复 start +1
和end - 1
(start + 1, end)
,(start, end - 1)
和
(start + 1, end - 1)
Idea a[start]
与数组中的其余元素匹配并获得最大结果.
public static int countPairs(int[] a){
Arrays.sort(a);
return countPairs(a,a.length,0,a.length-1);
}
public static int …
Run Code Online (Sandbox Code Playgroud) 我一直在努力理解如何以及何时使用HttpSecurity.requestMatchers
. 虽然我使用HttpSecurity.requestMatchers
但我有电话authorizeRequests
并antMatchers
指定安全规则。
我应该什么时候使用
http.requestMatchers()
.antMatchers("/secure/**","/patients/**","/patient/**", "/hello/**")
.and()
.authorizeRequests().antMatchers("/secure/**","/books/**","/book/**", "/hello/**")
.hasAnyRole("ADMIN","USER");
Run Code Online (Sandbox Code Playgroud)
超过
http
.authorizeRequests().antMatchers("/secure/**","/books/**","/hello/**", "/hello/**")
.hasAnyRole("ADMIN","USER");
Run Code Online (Sandbox Code Playgroud)
一个场景将帮助我理解用例 HttpSecurity.requestMatchers
我确实研究过requestMatchers,但我仍然不清楚
我可以通过命令创建一个docker容器
docker run <<image_name>>
Run Code Online (Sandbox Code Playgroud)
我可以通过命令创建服务
docker service create <<image_name>>
Run Code Online (Sandbox Code Playgroud)
这两者在行为上有什么区别?
我什么时候需要通过容器创建服务?
如何创建Map<String,List<Product>>
如下。这里,String
(的keyMap
) 是category
a 的Product
。
一种产品可以属于多个类别,如下例所示。
我正在尝试使用以下代码,但无法进行下一步操作:
products.stream()
.flatMap(product -> product.getCategories().stream())
. // how should I progress from here?
Run Code Online (Sandbox Code Playgroud)
结果应如下所示:
{电子=[p1,p3,p4], 时尚=[p1,p2,p4], 厨房=[p1,p2,p3], abc1=[p2], xyz1=[p3],pqr1=[p4]}
Product p1 = new Product(123, Arrays.asList("electonics,fashion,kitchen".split(",")));
Product p2 = new Product(123, Arrays.asList("abc1,fashion,kitchen".split(",")));
Product p3 = new Product(123, Arrays.asList("electonics,xyz1,kitchen".split(",")));
Product p4 = new Product(123, Arrays.asList("electonics,fashion,pqr1".split(",")));
List<Product> products = Arrays.asList(p1, p2, p3, p4);
Run Code Online (Sandbox Code Playgroud)
class Product {
int price;
List<String> categories;
public Product(int price) { …
Run Code Online (Sandbox Code Playgroud) 我正在尝试探索 terraform 在 AWS 中创建自动化基础设施。我不清楚如何将安全组附加到 terraform 中的 aws 实例。
例如,是否有任何属性可以指定安全组,如下所示
resource "aws_instance" "web" {
ami = "ami-a1b2c3d4"
instance_type = "t2.micro"
}
Run Code Online (Sandbox Code Playgroud) java ×4
java-8 ×3
java-stream ×2
algorithm ×1
collectors ×1
docker ×1
docker-swarm ×1
groupingby ×1
hashmap ×1
java-9 ×1
jvm-hotspot ×1
lambda ×1
publisher ×1
subscriber ×1
subscription ×1
terraform ×1