为什么:
#!/bin/bash
wtf=false
if [ $wtf ] || [ ! -f filethatexists.whatever ]
then
echo "WTF1"
fi
if [ ! -f filethatexists.whatever ]
then
echo "WTF2"
fi
Run Code Online (Sandbox Code Playgroud)
打印:
WTF1
而不是什么?特别令人困惑的是,第二种形式按预期工作,而第一种形式没有.
测试我可以专门插入我的Set和ListIterator的实现.
我知道一个常见的性能重构是替换简单for的System.arraycopy.
我想问一下:
system.arraycopy究竟何时开始有意义(考虑到它是本机方法调用).复制小事说,<32有什么优势吗?
这是我的印象,还是不可能简单地使用arraycopy复制(有效)这样的循环:
for (int j = 0; j < 2; ++j) {
vpr[m][s + j][i] = vr[j];
}
Run Code Online (Sandbox Code Playgroud)我一直在阅读有关生锈的博客,例如这个封闭让我想知道:
fn each<E>(t: &Tree<E>, f: &fn(&E) -> bool) {
if !f(&t.elem) {
return;
}
for t.children.each |child| { each(child, f); }
}
Run Code Online (Sandbox Code Playgroud)
为什么不能这样:
each<E>(t: &Tree<E>, f: &(&E) -> bool) {
if !f(&t.elem) {
return;
}
for t.children.each |child| { each(child, f); }
}
Run Code Online (Sandbox Code Playgroud)
也许我在类系统上遗漏了一些可以防止这种情况的东西.
我有一个组件,我想显示自定义jtooltip.这很简单,只需更改getTooltip方法即可.类似于位置和文字.
但是我也想改变计时器.如果鼠标位于组件的cellrenderer上,则应始终显示工具提示.如果它离开了所有这些,它应该变得不可见.我知道我可以使用TooltipManager来控制全局时间.但最好的解决方案可能只是短截线,并用鼠标滑块显示工具提示.但是,当我尝试这样做时(取消注册TooltipManager中的组件并将工具提示设置为可见,文本和位置正确,在鼠标监听器中)工具提示根本没有显示.我究竟做错了什么?
编辑:现在问题已经改变了!分为2个问题.
我的解决方案现在就是这个,但它失去了jtooltip总是有时令人沮丧地显示的阴影,并且如果鼠标退出弹出窗口本身就会隐藏它.如果弹出窗口甚至不是组件,如何通过弹出窗口过滤mouseexit事件?我可以根据lastPosition做一些黑客攻击,但这看起来很愚蠢,因为我真的不知道它的宽度.
private Popup lastPopup;
private final JToolTip tooltip = ...;
private Point lastPoint;
@Override public void mouseMoved(MouseEvent e) {
Point p = privateToolTipLocation(e);
if (p == null || p.equals(lastPoint)) {
return;
}
lastPoint = p;
tooltip.setTipText(privateToolTipText(e));
//copy
p = new Point(p);
SwingUtilities.convertPointToScreen(p, this);
Popup newPopup = PopupFactory.getSharedInstance().getPopup(this, tooltip, p.x, p.y);
if (lastPopup != null) {
lastPopup.hide();
}
lastPopup = newPopup;
newPopup.show();
}
@Override public void mouseExited(MouseEvent e) {
if (lastPopup != null && …Run Code Online (Sandbox Code Playgroud) 我相信大多数人都知道,如果函数输入大小为n,嵌套循环的复杂度为O(n ^ 2)
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
...
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这是类似的,通过一个类似的论点,但我不确定任何人都可以确认?
for(int i = 0, max = n*n; i < max; i++{
...
}
Run Code Online (Sandbox Code Playgroud)
如果是这样,我猜有些类型的代码,除了递归和子程序之外,其大O映射并不是很明显.