我很好奇,想知道为什么Java的可选没有提供peek类似的方法Stream的一个.
该peek方法的Javadoc所述的Stream界面态:
- @apiNote此方法主要用于支持调试,您希望在元素流经管道中的某个点时查看这些元素
这几乎完全描述了我的用例:
@Override
@Transactional
public User getUserById(long id) {
return repository.findById(id)
.peek(u -> logger.debug("Found user = {} by id = {}", u, id))
.orElseThrow(() -> new UserNotFoundException("id = " + id));
}
Run Code Online (Sandbox Code Playgroud)
(repository.findById返回Optional<User>(参见CrudRepository#findById))
但由于没有peek方法,因此无法编译Optional.
因此,如果没有peek方法,以上所有内容都将转换
@Override
@Transactional
public User getUserById(long id) {
Optional<User> userOptional = repository.findById(id);
if (userOptional.isPresent()) {
logger.debug("Found user = {} …Run Code Online (Sandbox Code Playgroud) 我已经在 Spring Boot 应用程序中配置了 oauth 并且当我尝试运行我的项目主类应用程序时无法开始说明:
'A component required a bean of type 'org.springframework.security.config.annotation.ObjectPostProcessor' that could not be found.
Run Code Online (Sandbox Code Playgroud)
我已经提到了几个类似的 Stack Overflow 问题和答案,但仍然没有找到任何解决方案。
这是WebSecurityConfiguration我添加的类:
@EnableOAuth2Sso
@Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception
{
http
.csrf()
.disable()
.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/index.html")
.permitAll()
.anyRequest()
.authenticated();
}
}
Run Code Online (Sandbox Code Playgroud)
这些是我的pom.xml依赖项:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>1.4.1.RELEASE</version>
</dependency> …Run Code Online (Sandbox Code Playgroud) 在 JUnit5 用户指南中提到,可用于的类型之一@ValueSource是java.lang.Class.
此功能的用例是什么?我该如何使用它?
@ParameterizedTest
@ValueSource(classes = {/*What goes here?*/})
void test(/*What goes here?*/) {
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试安装该requirements.txt文件skiptracer,但它一直说
ERROR: Could not find a version that satisfies the requirement pprint (from -r requirements.txt (line 7)) (from versions: none)
ERROR: No matching distribution found for pprint (from -r requirements.txt (line 7))
Run Code Online (Sandbox Code Playgroud)
我什至无法安装pprint
我需要获取不是由控制器创建的所有 Pod 的列表,以便我可以在节点上进行排空之前决定如何处理它们。
否则我会收到消息:
error: cannot delete Pods not managed by ReplicationController, ReplicaSet, Job, DaemonSet or StatefulSet (use --force to override) while running the drain.
Run Code Online (Sandbox Code Playgroud)
我可以通过运行并查看 Controlled By: 是否丢失来找到信息kubectl describe <pod>,但我想以编程方式搜索节点上的所有 pod,因为它kubectl describe不是为此设计的。我需要找到替代方法。
intJava中将两个s相除并没有什么特别之处。除非处理两种特殊情况之一:
ArithmeticException)Integer.MIN_VALUE / -1,JVMS 要求结果等于Integer.MIN_VALUE)(这个问题只针对这种情况)。有一种特殊情况不满足此规则:如果被除数是该
int类型的最大可能数量级的负整数,并且除数为-1,则发生溢出,结果等于被除数。尽管溢出,但在这种情况下不会引发异常。
在我的计算机上 ( x86_64) 本机分区产生SIGFPE错误。
当我编译以下 C 代码时:
#include <limits.h>
#include <stdio.h>
int divide(int a, int b) {
int r = a / b;
printf("%d / %d = %d\n", a, b, a / b);
return r;
}
int main() {
divide(INT_MIN, -1);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到结果(在 x86 上):
tmp …Run Code Online (Sandbox Code Playgroud) 我有以下 JPA 实体
@Entity
class UserEntity {
companion object {
fun fromParameters(uuid: String, email: String, password: String, firstName: String, lastName: String) =
UserEntity().apply {
this.uuid = uuid
this.email = email
this.password = password
this.firstName = firstName
this.lastName = lastName
}
}
@Id
lateinit var uuid: String
@Column(nullable = false, unique = true)
lateinit var email: String
@Column(nullable = false)
lateinit var password: String
@Column(nullable = false)
lateinit var firstName: String
@Column(nullable = false)
lateinit var lastName: String
}
Run Code Online (Sandbox Code Playgroud)
这是我检查 UNIQUE …
我用ViewModelProviders。但今天更新完库后,竟然有30条消息。据我了解ViewModelProviders不再可用,您需要替换它,我查看了developer.google,但不明白要替换什么?我的代码:
inline fun <reified T : ViewModel> FragmentActivity.injectViewModel(factory: ViewModelProvider.Factory): T {
return ViewModelProviders.of(this, factory)[T::class.java]
}
inline fun <reified T : ViewModel> Fragment.injectViewModel(factory: ViewModelProvider.Factory): T {
return ViewModelProviders.of(this, factory)[T::class.java]
}
Run Code Online (Sandbox Code Playgroud)
你能解释一下为什么它已经过时了吗?
java ×3
kotlin ×2
android ×1
h2 ×1
hibernate ×1
java-8 ×1
java-9 ×1
junit5 ×1
jvm ×1
jvm-hotspot ×1
kubectl ×1
kubernetes ×1
lambda ×1
oauth-2.0 ×1
optional ×1
pip ×1
pprint ×1
spring-boot ×1
spring-mvc ×1