我正面临着JVM和DNS的问题.
我正在阅读的所有内容(包括文档和此内容)都说我可以使用networkaddress.cache.ttl可以设置的JVM DNS缓存java.security.Security.setProperties,但是可以通过使用系统属性的标准方法来设置.我已成功将其更改为0,因此我的JVM中不再有缓存.
但是现在,在每次调用时InetAddress.getByName("mytest.com"),似乎我的JVM正在使用系统 DNS缓存(在我的情况下是Windows 8).实际上,在方法的两次调用之间,我已经更改了"mytest.com"的BIND9属性,但IP返回仍然是相同的.这是工作流程:
setCachePolicyInJVM(0) 在我的Java代码中.mytest.com为192.168.1.在BIND9中188,重启.InetAddress.getByName("mytest.com").getHostAddress(); - > 192.168.1.188mytest.com- > 192.168.1.在BIND9 160,重启.InetAddress.getByName("mytest.com").getHostAddress(); - > 192.168.1.188(如果没有缓存,则应为160).InetAddress.getByName("mytest.com").getHostAddress(); - > 192.168.1.160我已多次读过JVM不使用系统缓存,但这是错误的:它显然是这样.
我们如何绕过操作系统 DNS缓存强制每次调用新的DNS解析?
我想为具有类型为a的id字段的记录指定类型Uuid.所以,我正在使用可扩展记录.类型如下:
type alias WithId a = { a | id : Uuid }
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.但后来我为这种类型创建了一个Json.Encoder- 也就是类型的函数WithId a -> Value- .我需要一种方法来编码底层值,所以我想采用类型的第一个参数a -> Value.由于我知道a是一个记录,我可以放心地假设它被编码为JSON对象,即使Elm没有公开数据类型Value.
但是,当我创建这样的函数时,我得到一个编译错误:
The argument to function `encoder` is causing a mismatch.
27| encoder a
^
Function `encoder` is expecting the argument to be:
a
But it is:
WithId a
Hint: Your type annotation uses type variable `a` which means any type of value
can flow through. …Run Code Online (Sandbox Code Playgroud) records functional-programming compiler-errors higher-order-functions elm
我有很多类看起来像这样:
class Foo(val:BasicData) extends Bar(val) {
val helper = new Helper(val)
val derived1 = helper.getDerived1Value()
val derived2 = helper.getDerived2Value()
}
Run Code Online (Sandbox Code Playgroud)
...除了我不想在构造函数的末尾之外保留"helper"的实例.在Java中,我会做这样的事情:
public class Foo {
final Derived derived1, derived2;
public Foo(BasicData val) {
super(val);
Helper helper = new Helper(val);
derived1 = helper.getDerived1Value();
derived2 = helper.getDerived2Value();
}
}
Run Code Online (Sandbox Code Playgroud)
那么我如何在Scala中做类似的事情呢?我知道使用apply方法创建一个与该类同名的辅助对象:我希望有一些更简洁的东西.