我有两种方法看起来像这样.一种是通用方法,另一种不是.
<T> void a(final Class<T> type, final T instance) {
}
Run Code Online (Sandbox Code Playgroud)
void b(final Class<?> type, final Object instance) {
if (!Objects.requireNotNull(type).isInstance(instance)) {
throw new IllegalArgumentException(instance + " is not an instance of " + type);
}
// How can I call a(type, instance)?
}
Run Code Online (Sandbox Code Playgroud)
我怎么能说a()与type和instance从b()?
我问了一个答案,如何绑定一个命名的注入点。
而且我不知道如何将工厂绑定到合格的注入点。
class SomeResource {
@Inject
@Some // is a @Qualifier, of course.
private MyType qualified;
}
Run Code Online (Sandbox Code Playgroud)
我准备了一家工厂
class SomeFactory extends Factory<MyType> {
}
Run Code Online (Sandbox Code Playgroud)
我坚持为此创建活页夹
class SomeBinder extends AbstractBinder {
@Override protected void configure() {
// @@?
}
}
Run Code Online (Sandbox Code Playgroud)
我实际上想知道如何使用ServiceBindingBuilder#qualifiedBy。
使用给定的应用程序
@ApplicationPath("/api")
public class MyApplication {
}
Run Code Online (Sandbox Code Playgroud)
UriInfo#getBaseUri给了我一个应用程序路径。
@Context
private UriInfo uriInfo
uriInfo.getBaseUri(); // http://address/<context-path>/api
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得上下文路径?
如何获取上下文路径的完整 URL?
http://address/<context-path>
Run Code Online (Sandbox Code Playgroud)
更新
我目前使用这个答案中的代码。
@Context
private HttpServletRequest servletRequest;
final URI contextUri
= URI.create(servletRequest.getRequestURL().toString())
.resolve(servletRequest.getContextPath());
Run Code Online (Sandbox Code Playgroud)
还有其他建议吗?
我有一个可以为空的列表;
List<T> list; // may or may not null
Run Code Online (Sandbox Code Playgroud)
我想与消费者一起处理每个元素。
到目前为止,我做到了。
ofNullable(list)
.map(List::stream)
.ifPresent(stream -> stream.forEach(e -> {}));
Run Code Online (Sandbox Code Playgroud)
或者
ofNullable(eventDataList).ifPresent(v -> v.forEach(e -> {}));
Run Code Online (Sandbox Code Playgroud)
有没有简单或简洁的方法来做到这一点?
我的Profile类有一个集合属性。
class Profile {
private List<String> aliases;
}
Run Code Online (Sandbox Code Playgroud)
如何查询选择包含任何给定集合的Profiles ?aliases
比如说,选择别名包含 [ a、b、c] 中的任何一个的配置文件?
我正在研究 CyclicBarrier ,并编写了这个演示。
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import static java.util.concurrent.ThreadLocalRandom.current;
public class CyclicBarrierDemo {
public static void main(final String[] args) {
final int threads = 100;
final CyclicBarrier barrier
= new CyclicBarrier(threads, () -> System.out.println("tripped"));
final int rounds = 5;
for (int i = 0; i < threads; i++) {
new Thread(() -> {
for (int j = 0; j < rounds; j++) {
try {
Thread.sleep(current().nextLong(1000L));
barrier.await();
} catch (InterruptedException | BrokenBarrierException e) {
e.printStackTrace(System.err);
return;
}
} …Run Code Online (Sandbox Code Playgroud) 我正在使用wildfly-maven-plugin进行集成测试.
如何更改端口默认号码(8080,8443)?
我找不到这些端口号的任何配置属性.
UPDATE
我发现了这个,端口号也改变了.但是起始目标未能产生"在XX秒内未能启动"可能一些信令程序不知道改变的端口.
<executions>
<execution>
<id>wildfly-start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>wildfly-deploy</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
<execution>
<id>wildfly-undeploy</id>
<phase>post-integration-test</phase>
<goals>
<goal>undeploy</goal>
</goals>
</execution>
<execution>
<id>wildfly-shutdown</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
Run Code Online (Sandbox Code Playgroud)
jvmArgs<configuration>
<jvmArgs>-Djboss.socket.binding.port-offset=40000</jvmArgs>
</configuration>
Run Code Online (Sandbox Code Playgroud)
端口号仍为默认值.
14:25:34,244 INFO ... Undertow HTTP listener default listening on 127.0.0.1:8080
14:25:35,107 INFO ... Undertow HTTPS listener https listening on 127.0.0.1:8443
14:25:40,183 INFO ... Http management interface listening on http://127.0.0.1:9990/management
14:25:40,183 INFO ... …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我的存储库界面,如下所示。
interface SomeRepository extends JpaRepository<Some, Long> {
@org.springframework.lang.Nullable
Some findByKey(
@org.springframework.lang.NonNull
@javax.validation.constraint.NotNull
final String key);
}
Run Code Online (Sandbox Code Playgroud)
我发现这些约束没有按预期工作。
@Test
void findByKeyWithNullKey() {
repository.findByKey(null);
}
Run Code Online (Sandbox Code Playgroud)
测试用例只是通过了。
我该如何运作?
我刚刚发现 具有Instant#ofEpochSecond(epochSecond)最小值/最大值。
这里是源代码。
// Instant.java
/**
* The minimum supported epoch second.
*/
private static final long MIN_SECOND = -31557014167219200L;
/**
* The maximum supported epoch second.
*/
private static final long MAX_SECOND = 31556889864403199L; // << I WANT THIS VALUE!
Run Code Online (Sandbox Code Playgroud)
我如何以MAX_SECOND编程方式获取?
我试图弄清楚Range,
final var range = ChronoField.INSTANT_SECONDS.range();
log.debug(" minimum: {}", range.getMinimum());
log.debug(" largestMinimum: {}", range.getLargestMinimum());
log.debug(" maximum: {}", range.getMaximum());
log.debug("smallestMaximum: {}", range.getSmallestMaximum());
Run Code Online (Sandbox Code Playgroud)
并且没有运气。
03:53:36.120 [ main] DEBUG - minimum: -9223372036854775808
03:53:36.122 [ main] …Run Code Online (Sandbox Code Playgroud) java ×5
collections ×1
epoch ×1
generics ×1
hk2 ×1
instant ×1
java-stream ×1
java-time ×1
jax-rs ×1
jersey ×1
jpa ×1
jpql ×1
lambda ×1
maven ×1
spring ×1
spring-data ×1
testng ×1
unit-testing ×1
unsafe ×1
wildfly ×1