我上课了
public class Answer<T> {
private T data;
public Answer(T data) {
this.data = data;
}
public Answer() {
}
public T getData() {
return data;
}
public Answer<T> setData(T data) {
this.data = data;
return this;
}
}
Run Code Online (Sandbox Code Playgroud)
我想简化Lombok.
如果我添加注释@AllArgsConstructor比我看不到默认构造函数.
@Data
@AllArgsConstructor
public class Answer<T> {
private T data;
public Answer<T> setData(T data) {
this.data = data;
return this;
}
}
Run Code Online (Sandbox Code Playgroud)
是否有可能同时拥有两个构造函数Lombok?
使用Lombok,是否可以指定一个arg构造函数?
我的目的是使用Lombok注释创建一个构造函数,如下所示.
class MyClass {
private String param;
private Integer count;
public MyClass(String param) {
this.param = param;
}
}
Run Code Online (Sandbox Code Playgroud) 是什么在点龙目岛标注@NonNull的方法?
class MyClass {
@NonNull
void run() {
// code here
}
}
Run Code Online (Sandbox Code Playgroud)
我们检查MyClass类的实例(MyClass obj == null)吗?
我正试图找出一个角色是否属于一个字符串.
var s = "abcdef"
var result = s.any('d')
Run Code Online (Sandbox Code Playgroud)
但我无法理解这种语法.来自docs:
fun CharSequence.any(predicate: (Char) -> Boolean): Boolean
Run Code Online (Sandbox Code Playgroud)
如何将谓词传递给函数?
这段代码
(4 :: Integer) / 2
Run Code Online (Sandbox Code Playgroud)
会导致错误:
No instance for (Fractional Integer) arising from a use of ‘/’
In the expression: (4 :: Integer) / 2
In an equation for ‘it’: it = (4 :: Integer) / 2
Run Code Online (Sandbox Code Playgroud)
为什么?
我需要指明
fromIntegral(4 :: Integer) / 2
Run Code Online (Sandbox Code Playgroud)
得到一个结果.但是如果我需要一个实数而不是2.0呢?
我在本地计算机上运行了一个Web应用程序.要访问它,我可以使用localhost:8080.但是当我尝试使用http://127.0.0.1:8080地址时,我的浏览器会说:The 127.0.0.1 page isn’t working.
Ping到它不起作用:
ping 127.0.0.1:8080
ping: cannot resolve 127.0.0.1:8080: Unknown host
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我有一个代码
object App {
def main(args: Array[String]) = print {CL().f()()()}
}
case class CL() {
def f()()() = 1
}
Run Code Online (Sandbox Code Playgroud)
你可以看到一个方法调用f()()().但是如果我执行f()它会返回相同的结果.
那么在f()()()和f()Scala之间有什么区别?
我目前正在试图弄清楚Memento Pattern的工作原理.我坚持Caretaker上课?拥有它真的很重要吗?我的意思是我可以在没有这门课的情况下使用纪念品.请参阅下面的代码.
public class Originator {
private String state;
private Integer code;
private Map<String, String> parameters;
// Getters, setters and toString were omitted
public Memento save() {
return new Memento(this);
}
public void restore(Memento memento) {
this.state = memento.getState();
this.code = memento.getCode();
this.parameters = memento.getParameters();
}
}
Run Code Online (Sandbox Code Playgroud)
这是Memento实施.
public class Memento {
private String state;
private Integer code;
private Map<String, String> parameters;
public Memento(Originator originator) {
Cloner cloner = new Cloner();
this.state = cloner.deepClone(originator.getState());
this.code = cloner.deepClone(originator.getCode());
this.parameters …Run Code Online (Sandbox Code Playgroud) 假设我有一个带有注释的类,例如:
@MyConfig
class MyConfiguration {
@MyParameter
String parameter;
}
Run Code Online (Sandbox Code Playgroud)
如果我知道这个类的一个实例存在(例如,一个是在另一个线程中构造的),我如何才能在其他地方获得对该实例的引用。我试图通过它的@Annotation 找到该实例。
我想为变量设置一个默认值。但是我的 Scala 编译器说:
Error:(20, 16) unbound placeholder parameter
val p: T = _
^
Run Code Online (Sandbox Code Playgroud)
这是代码。
object InverseFunctionsExample extends App {
type D = Double
def f(x: D): D = 5 * x + 10
def g(x: D): D = 0.2 * x - 2
printMessage(isInversible(f, g))
def printMessage(inv: Boolean): Unit = {
if (inv) print("YES!") else print("NOPE!")
}
def isInversible[T](f: (T) => T, g: (T) => T): Boolean = {
val p: T = _
if (f(p) == g(p))
true …Run Code Online (Sandbox Code Playgroud)