cost 82 ms
在 CompletableFuture 中返回 autocloseable object 并在 whenComplete 中使用它 - Return autocloseable object inside a CompletableFuture and use it in whenComplete

我想在 CompletableFuture 中返回一个可自动关闭的 object 并在 whenComplete 中使用它,而无需稍后手动关闭它。 这是我试过的代码,但当然它不会工作,因为当我返回 Jedis object 时它会自动关闭。我没有任何其他想法。 ...

使用 try-with-resources 时,“TypedArray 应该被回收”是否是 Lint 中的误报? - Is "TypedArray should be recycled" a false positive in Lint when using try-with-resources?

我在这里阅读了关于回收TypedArray的几十个问题,但我想它们有点太旧了,而且在我们可以广泛使用try-with-resource语句之前就已经写好了,所以他们都没有谈论使用AutoCloseable的实现TypedArray ,自API 级别 31起存在所以问题仍然存在:这是 Lint 中的 ...

具有 AutoCloseable 类型和返回布尔值的 lambda 的 Kotlin `use` - Kotlin `use` with AutoCloseable type and a lambda returning Boolean

这一定很简单,但我已经用头撞了半个小时了......这是我的旧的,异常不安全的代码: 我想重写它以使用use ,如下所示: 但是 Kotlin 给了我一个错误: 或者,我说“好吧,我不懂简洁的 lambda 语法,让我用fun ”,然后我试试这个: Kotlin 仍然抱怨: 我 ...

关闭仅存在于“Either”中的(自动)Closables - Closing (Auto)Closeables that exist only in `Either`

我目前面临正确关闭永远不会离开其包含Either的资源的问题。 相关代码如下所示: 关闭创建的MyRes最惯用的方法是什么? 在map之前关闭它会阻止extractData访问它,在map之后我无法再通过Either的操作访问它。 在extractData中关闭它会严重限制可组合性。 目前我有一个 ...

使用try-with-resources时,某些自定义类实现Closeable接口时如何自动创建FileInputStream实例 - How FileInputStream instance is automatically created when Closeable interface is implemented by some custom class when using try-with-resources

我一直在使用 try-with-resources 语句。 对资源使用 try 的好处主要是避免指定 finally 块来关闭资源。 这就是我的研究过程开始的地方。 在做了一些调试之后,我发现FileReader 扩展了 InputStreamReader 。 在 FileReader 类中 ...

为什么 class 实现 Autoclosable 接口的关闭方法比 Sql 连接关闭先被调用? - Why close method of class that implements Autoclosable interface is called first than Sql connection close?

我找到了提交失败时回滚事务的解决方案,并且效果很好。 但是你能解释一下为什么先调用 Autorollback object 关闭方法而不是连接关闭? 自动回滚 class: 使用 Autorollback 的服务方法示例: 为什么 Autorollback 的 close 方法会起作用?如果连接关 ...

声明多个有效的最终资源时,try-with-resource 是否不安全? - Is try-with-resource not safe when declaring multiple effectively final resources?

由于 Java 9 我们可以在 try-with-resources 中有效地使用最终变量。 下面的示例展示了其中一个资源初始化引发异常的情况。 当我运行这个示例时,我得到的唯一 output 是 RuntimeException,这意味着 Resource1 没有关闭。 这是意料之中的,因为它没 ...

将方法标记为返回现有的可关闭对象,以避免在使用站点出现虚假警告 - Mark a method as returning an existing closeable to avoid spurious warning at usage site

给定一个 class MyClass使用内部可关闭 object, myCloseable并提供返回它的方法getCloseable() ; Eclipse,如果配置了这种可关闭的资源警告,每次有人调用getCloseable()时都会系统警告,说可关闭的“可能不会在这个位置关闭”。 很高兴有这样 ...

对没有任何参考的资源使用“try with resources” - Using “try with resources” for resources created without any reference

考虑以下情况: 这是在try资源中创建了三个资源的情况: Connection 、 Statement和ResultSet 。 try 块结束后这三个资源会发生什么? 它们是否都会被关闭,即使它们没有对它们的任何引用,还是只会关闭resultSet ? 在尝试使用资源块时声明AutoClosea ...

创建 Flux.fromIterable 后如何运行 onClose 操作? - How to run onClose operation after creating Flux.fromIterable?

假设我们需要根据Closeable资源的内容创建Flux 。 为清楚起见,说有一个BufferedReader要转换为Flux<String> 。 让我们假设iteratorOfLines产生有限的项目集。 我正在寻找一种关闭BufferedReader的方法,当Flux已使用其中的所 ...

如何为 java.util.logging.FileHandler 使用 try-with-resources? - How to use try-with-resources for java.util.logging.FileHandler?

我有以下代码并使用java.util.logging.FileHandler创建日志文件。 在这种情况下,我应该手动关闭 finally 块中的资源。 此代码有效。 现在,我认为它可以实现Autocloseable接口。 因此,我决定对FileHandler使用try-with-resources ...


 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM