我正准备编译但出现上述错误。基本上这就是我所拥有的。
java.lang.Object obj = Account::getTestaccount;
Run Code Online (Sandbox Code Playgroud)
Account 是一个类,它具有使用 setter 和 getter 方法声明的 TestAccount 对象。
有人可以告诉我为什么这会引发错误。谢谢。
使用 HBase 和 Parquet,我编写了代码来从 HBase 获取值并将值映射到 Object 类,但是我无法使用 Dataset 用 Parquet 复制它。
HBase:
JavaPairRDD<ImmutableBytesWritable, Result> data = sc.newAPIHadoopRDD(getHbaseConf(),
TableInputFormat.class, ImmutableBytesWritable.class, Result.class);
JavaRDD<List<Tuple3<Long, Integer, Double>>> tempData = data
.values()
//Uses HBaseResultToSimple... class to parse the data.
.map(value -> {
SimpleObject object = oParser.call(value);
// Get the sample property, remove leading and ending spaces and split it by comma
// to get each sample individually
List<Tuple2<String, Integer>> samples = zipWithIndex((object.getSamples().trim().split(",")));
// Gets the unique identifier for that sp.
Long sp = object.getPos(); …Run Code Online (Sandbox Code Playgroud) 我编写了一段简单的代码来使用 java 8 api 解析日期。我还研究了有关此主题的各种其他堆栈溢出问题,但未能解决该错误。
package com.test.java8api;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.ResolverStyle;
import java.util.Locale;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE, MM/DD/YYYY - HH:mm", Locale.ENGLISH).withResolverStyle(ResolverStyle.STRICT);
LocalDateTime date = LocalDateTime.parse("Sun, 04/22/2018 - 09:45",formatter);
System.out.println(date);
}
}
Run Code Online (Sandbox Code Playgroud)
错误日志是
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Sun, 04/22/2018 - 09:45' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {DayOfWeek=7, WeekBasedYear[WeekFields[SUNDAY,1]]=2018, MonthOfYear=4, DayOfYear=22},ISO resolved to 09:45 of type java.time.format.Parsed
at …Run Code Online (Sandbox Code Playgroud) 我想分析.class文件并获取有关哪个类使用哪个其他类的信息。
jdeps 是一个命令行工具,它允许您在控制台中显示一些信息,但我想避免调用外部工具并抓取命令行输出。
我知道方法签名包括方法名称及其参数列表。
但是throws Exception呢?
public List<ServiceStatusVo> listServiceStatuses() throws RetrieverException {
...
return list;
}
Run Code Online (Sandbox Code Playgroud)
如果不包括在内,那么为什么我不能传入以下 lambda:
() -> listServiceStatuses()
Run Code Online (Sandbox Code Playgroud)
但我可以通过
() -> {
try {
return listServiceStatuses();
} catch (RetrieverException e) {
}
}
Run Code Online (Sandbox Code Playgroud)
我也可以再次扔掉它
() -> {
try {
return listServiceStatuses();
} catch (RetrieverException e) {
throw e;
}
}
Run Code Online (Sandbox Code Playgroud)
我知道Supplier<T>函数式接口,如果 throws不是方法签名的一部分,那真的让我感到困惑。
谢谢您的帮助。
我需要从给定的超级列表中获取子列表,如下所述。
假设我有一个“Person”对象的超级列表,如下所示:
List<Person> personsList = new ArrayList<>();
personsList.add(new Person("John", 28));
personsList.add(new Person("Paul", 29));
personsList.add(new Person("Adam", 30));
personsList.add(new Person("Peter", 31));
personsList.add(new Person("Pat", 32));
Run Code Online (Sandbox Code Playgroud)
让 Person 类定义如下:
class Person {
public String name;
public int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
@Override
public String toString() {
return name + ": " + age;
}
}
Run Code Online (Sandbox Code Playgroud)
给定这样的子列表:
String [] names = {"John", "Paul", "Adam"};
List<String> namesList = Arrays.asList(names);
Run Code Online (Sandbox Code Playgroud)
我想获取名称为John,Paul和的 Person 对象 …
我正在尝试将 Student 对象列表转换为一个映射,其中键是整数(即 Student 对象的 rollno 字段),Value 是 Student 对象本身。
以下是我编写的代码:
package fibonacci;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class MApfor {
public static void main(String[] args) {
List<Student> maplist=new ArrayList<>();
maplist.add(new Student(1, "pavan"));
maplist.add(new Student(2, "Dhoni"));
maplist.add(new Student(3, "kohli"));
maplist.forEach(System.out::println);
Map<Integer,Student> IS=new HashMap<>();
IS = maplist.stream().collect(Collectors.toMap(a -> a.getRollNo,a);
}
}
Run Code Online (Sandbox Code Playgroud)
每当我尝试写最后一行时,即
IS = maplist.stream().collect(Collectors.toMap(a -> a.getRollNo,a);
Run Code Online (Sandbox Code Playgroud)
我无法检索 rollNo 字段,eclipse 没有显示建议,即每当我键入 a.get 将 rollNo 分配给键时,我无法这样做。
请提出我面临的问题。
package fibonacci;
public class Student {
public int rollNo; …Run Code Online (Sandbox Code Playgroud) 我正在尝试Map根据条件逻辑和挣扎修改 a的键。我是 Java 8 流 API 的新手。假设我有一张这样的地图:
Map<String, String> map = new HashMap<>();
map.put("PLACEHOLDER", "some_data1");
map.put("Google", "some_data2");
map.put("Facebook", "some_data3");
map.put("Microsoft", "some_data4");
Run Code Online (Sandbox Code Playgroud)
当我想做的是PLACEHOLDER根据布尔条件找到引用并有条件地将该键更改为其他内容。我觉得它应该是什么样的下方,但这并不甚至编译过程的。
boolean condition = foo();
map = map.entrySet().stream().filter(entry -> "PLACEHOLDER".equals(entry.getKey()))
.map(key -> {
if (condition) {
return "Apple";
} else {
return "Netflix";
}
}).collect(Collectors.toMap(e -> e.getKey(), Map.Entry::getValue));
Run Code Online (Sandbox Code Playgroud)
我发现这个问题让我觉得也许我不能用 Java 8 流 API 来做到这一点。希望有比我更擅长的人知道如何做到这一点。如果你想玩它,Ideone 链接。
我正在使用 AXIS (1.4) 客户端来调用 SOAP Web 服务,JDK 版本为 8。某些 SOAP 服务调用出现以下间歇性错误。在负载条件下,1000 个请求中有 5-10 个请求会发生这种情况。
Caused by: org.apache.axis.AxisFault: java.util.ConcurrentModificationException
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:223) ~[axis-1.4.jar:na]
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:130) ~[axis-1.4.jar:na]
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1104) ~[axis-1.4.jar:na]
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) ~[na:na]
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source) ~[na:na]
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) ~[na:na]
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) ~[na:na]
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[na:na]
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[na:na]
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) ~[na:na]
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) ~[na:na]
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) ~[na:na]
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:241) ~[axis-1.4.jar:na]
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696) ~[axis-1.4.jar:na]
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435) ~[axis-1.4.jar:na]
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62) ~[axis-1.4.jar:na]
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206) ~[axis-1.4.jar:na]
at org.apache.axis.client.Call.invokeEngine(Call.java:2782) …Run Code Online (Sandbox Code Playgroud) 我有 Tomcat 9.0.12 和 Java JDK/JRE 1.8.0_191。我正在尝试配置 SSL/TLS。我已经像这样更改了我的 server.xml 文件:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" />
<Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="C:\my_certificate.pfx"
keystorePass="my_password" keystoreType="PKCS12" />
Run Code Online (Sandbox Code Playgroud)
我的证书文件是 *.pfx 格式。我通过命令行使用 startup.bat 命令运行 tomcat 服务器。但是我收到了这样的错误(在我的 catalina.log 中):
...
05-Nov-2018 16:33:57.080 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
05-Nov-2018 16:33:57.190 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
05-Nov-2018 16:33:57.205 SEVERE [main] org.apache.catalina.util.LifecycleBase.handleSubClassException Failed to initialize component [Connector[org.apache.coyote.http11.Http11Protocol-443]]
org.apache.catalina.LifecycleException: Protocol handler instantiation failed
at org.apache.catalina.connector.Connector.initInternal(Connector.java:904)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
at org.apache.catalina.core.StandardService.initInternal(StandardService.java:533) …Run Code Online (Sandbox Code Playgroud)