我有一个在 Linux 上跟踪的目录git
,我将其复制到 mac OS。由于错误git status
,多个文件未被跟踪filename: File name too long
。一个文件名(及其相对路径)为 393 个字符。是否有 4096 个字符的限制(Windows 除外)?[参考] 我的core.longpaths
设置是true。(同样设置core.precomposeunicode
为 true,但可能不相关)。有什么建议吗?
Java中是否有语法将变量列表初始化为数组中的相应对象?
String hello, world;
String[] array = {"hello", "world"};
//I want:
{hello, world} = array;
//instead of:
hello = array[0];
world = array[1];
Run Code Online (Sandbox Code Playgroud)
我想我从Matlab回忆起这种方便的语法,但是我没有注意到在Java中实现这一点的方法.这种语法可以帮助我组织我的代码.具体来说,我想在一个函数中输入一个对象数组而不是多个参数中的每个数组成员,然后通过在方法范围内声明变量来开始该方法的代码,以便对数组成员进行命名访问.例如:
String[] array = {"hello", "world"};
method(array);
void method(array){
String {hello, world} = array;
//do stuff on variables hello, world
}
Run Code Online (Sandbox Code Playgroud)
感谢您的建议.-Daniel
我读到使用KeyBindings比使用KeyListeners更好.我看到KeyBindings如何对特定键的特定反应有用; 但我也试图检测键盘上任意键的按下/释放:有没有办法用KeyBindings做到这一点?
例如,我通常会使用KeyBindings来处理单个键,如下所示:
InputMap iMap = component.getInputMap();
ActionMap aMap = component.getActionMap();
iMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter without modifiers");
aMap.put("enter without modifiers", new AbstractAction(){
public void actionPerformed(ActionEvent a){
System.out.println("Enter pressed alone");
});
Run Code Online (Sandbox Code Playgroud)
因此,我正在考虑使用这样的方法来检测任何按键:
iMap.put(KeyStroke.getKeyStroke(KeyEvent.KEY_PRESSED, 0), "any key was pressed");
aMap.put("any key was pressed", new AbstractAction(){
public void actionPerformed(ActionEvent a){
System.out.println("some key was pressed, regardless of which key...");
});
Run Code Online (Sandbox Code Playgroud)
有没有办法实现这个目标?
另外,有没有办法用任何修饰符组合捕获它们的KeyBinding?例如,无论是否保留修饰符,或者如果同时保持任何组合的ctrl-alt等,都要映射Enter-action?
非常感谢,Dan
交叉发布于:http://www.javaprogrammingforums.com/whats-wrong-my-code/26194-how-detect-any-key-press-keybindings.html#post103862