JVM决定在编译时调用哪个重载方法.我有一个例子:
public class MainClass{
public static void go(Long n) {System.out.println("takes Long ");}
public static void go(Short n) {System.out.println("takes Short ");}
public static void go(int n) {System.out.println("takes int ");}
public static void main(String [] args) {
short y = 6;
long z = 7;
go(y);
go(z);
go((Short)y);
}
}
Run Code Online (Sandbox Code Playgroud)
根据我的理解,它应该打印以下内容:
takes Short
takes Long
takes Short
Run Code Online (Sandbox Code Playgroud)
...但实际输出是:
takes int
takes Long
takes Short
Run Code Online (Sandbox Code Playgroud)
但是,如果我有以下三个功能:
public static void go(Integer n) {System.out.println("takes Integer");}
public static void go(Long n) {System.out.println("takes Long ");}
public static …Run Code Online (Sandbox Code Playgroud) 我是clojure的新手,最初我要通过Clojure.org和cheatbook.
我想知道conj列表和向量的不同行为的确切原因是什么.
(conj [1 2 3] 4)
[1 2 3 4]
(conj (list 3 2 1) 4)
(4 3 2 1)
Run Code Online (Sandbox Code Playgroud)
当我使用它与列表时,它在第一个位置添加元素,并在向量添加到最后位置.
我创建了一个函数来检查我的第一个字符串是否以第二个字符串结尾.
在Java中我们有现成的方法来检查这个,但在Clojure中我找不到这样的方法所以我编写了自定义函数如下:
(defn endWithFun [arg1 arg2]
(= (subs arg1 (- (count arg1) (count arg2)) (count arg1)) arg2))
Run Code Online (Sandbox Code Playgroud)
输出:
> (endWithFun "swapnil" "nil")
true
> (endWithFun "swapnil" "nilu")
false
Run Code Online (Sandbox Code Playgroud)
这是按预期工作的.
我想知道,有没有类似的选择?同样在我的情况下,我比较敏感.我也想忽略区分大小写.
如果我将margin-top放到第一个列表项(LI),那么margin在ul之外.
最后一项和margin-bottom也是一样的.但保证金左/保证金权利按预期运作.
为什么这样,是否可以修复?
请参阅:小提琴链接
干杯
我有个问题.
我需要一个Javascript函数,它将变量值增加(增量)4,当变量值为20时,将变量值设置为0并再次将其递增4,依此类推......
我认为我需要循环和if条件,但我不知道如何实现这个...
例
结果必须是:
x = 0; 然后x = 4,x = 8,x = 12,x = 16,x = 20,x = 0,x = 4 ....
谢谢