小编St.*_*rio的帖子

无法列出$ HOME目录中的所有文件

我安装了最新版本,cygwin并希望列出我的目录中的所有文件$HOME(在特殊.vimrc配置文件中).我输入ls -l并查看0个文件,但是当我尝试通过vim打开文件时,它没问题.实际上(2 TAB秒后):

在此输入图像描述

怎么了?

linux bash cygwin

0
推荐指数
1
解决办法
83
查看次数

如何获取表单ID属性位于

我有以下表格:

<form id="formId">
    <!-- some tags -->
    <div>
        <!-- some other divs or something else -->
            <input type="radio" onclick="handler(this) />
    </div>
</form>
Run Code Online (Sandbox Code Playgroud)

函数处理程序的位置如下:

var handler = function(elem){
    init();
    var clicked = //here should be form id
    //other staff
};
Run Code Online (Sandbox Code Playgroud)

如何获取随附表格的ID?假设网页上只有一个表单.

我正在寻找pure-js以及jQuery解决方案.

html javascript jquery

0
推荐指数
1
解决办法
96
查看次数

从类型变量调用静态方法

我上课了:

public class AbstractHandler {
    public static void handle(){ 
        throw new UnsupportedOperationException("Not implemented");
    }
}
Run Code Online (Sandbox Code Playgroud)

这将有一些数字子类.

我还有以下类将使用该类:

public class Consumer<T extends AbstractHandler>{

    public static void handle(){
        //I need to call the method 
        //T.handle() somehow
        //Is that possible?
    }
}
Run Code Online (Sandbox Code Playgroud)

java generics

0
推荐指数
1
解决办法
55
查看次数

rvalue对函数类型的引用

众所周知,返回类型的函数调用是函数的rvlaue是左值.

如果结果类型是左值引用类型或对函数类型的右值引用,则函数调用是左值;如果结果类型是对象类型的右值引用,则为xvalue,否则为prvalue.

#include <iostream>

int a(){ return 1; }

int foo(){ return 1; }

int (&&bar())(){ return a; }

int main()
{
    bar() = foo; //error: cannot convert 'int()' to 'int()' in assignment
}
Run Code Online (Sandbox Code Playgroud)

该诊断消息有什么问题?

c++ rvalue

0
推荐指数
1
解决办法
128
查看次数

读取未初始化的变量

读取未初始化的变量会导致未定义的行为,例如

#include <iostream>

int main()
{
    int a;
    std::cout << a << std::endl; // undefined behavior
}
Run Code Online (Sandbox Code Playgroud)

有人可以对这个事实给出正式的解释吗?

c++ language-lawyer

0
推荐指数
1
解决办法
976
查看次数

为什么我们可以在其类范围之外定义私有成员

我认为私有成员甚至不存在于类范围之外,所以我们无法访问它们.但考虑一下:

#include <iostream>

class A
{
private:
    static const int a = 1;
};

const int A::a; //Access to the private member outside the class scope
                //the compiler doesn't compain

int main ()
{
    std::cout << A::a << std::endl; //compile-time error
}
Run Code Online (Sandbox Code Playgroud)

为什么允许?这只是为了方便吗?

c++ static

0
推荐指数
1
解决办法
379
查看次数

析构函数抛出异常

我试图理解为什么析构函数抛出异常是一个非常糟糕的主意.通过谷歌搜索,我理解如果析构函数抛出,比如说,在块范围对象的销毁过程中,对象的销毁停止了,如果其他对象析构函数没有调用则会导致内存泄漏.

但就其本身而言,析构函数抛出异常是如此糟糕?例如(完整示例):

struct A
{
    int a;
    char b;
    A() : a(10), b('a') { }
    ~A(){ throw std::exception(); }
};

int main()
{
    A a; //destructor throws, but there're no more objects to destruction 
         //therefore I think there's no memory leak
}
Run Code Online (Sandbox Code Playgroud)

我们在上面的程序中得到了UB吗?

c++ destructor

0
推荐指数
1
解决办法
120
查看次数

设计继承类

我正在阅读J. Bloch的Effective Java,现在我正处于继承部分的设计课程中.他描述了所谓的自用模式,据我所知,我们不能在其他可覆盖的方法中使用可覆盖的方法.

所以我的问题是关于如何让客户了解自我使用.我们是否应该明确地提到它Javadocs:

/**
* This class is self-use, thus it cannot be inherited.
*/
Run Code Online (Sandbox Code Playgroud)

或者我们甚至应该拒绝这种诱惑self-use.

示例代码:我们是否应该如上所述记录该类,或者我们必须避免这种自我使用?

public class MyClass{

    public void overrideMe(){ 
        //something
        ovMe(); 
    }

    public void ovMe(){
         //some staff
    }
}
Run Code Online (Sandbox Code Playgroud)

java inheritance

0
推荐指数
1
解决办法
114
查看次数

是否正在使用低等原语如等待被认为是坏的?

我正在实现Future共享计算的接口.即一个线程执行计算,其他线程需要相同的结果只需要通过Future.所以,我已经阅读了Object#wait()方法文档并确定它完全满足我的需求.以下是我对Future#get()方法的实现方式:

public class CustomFuture implements Future<Collection<Integer>> {

    private AtomicBoolean started;
    private Exception computationException;
    private boolean cancelled;
    private Collection<Integer> computationResult;
    private Object waitForTheResult = new Object();

    public Collection<Integer> get(){
        if(started.compareAndSet(false, true))
            //start the computation    //notifyAll() is called after finishing the computation here.
        while(computationResult == null){
            if(cancelled)
                throw new CancellationException();
            if(computationException != null)
                throw new ExectuonException();
            synchronized(waitForTheResult){
                waitForTheResult.wait();
            }
        }
        return computationResult;
    }             
    //The rest of methods
}
Run Code Online (Sandbox Code Playgroud)

由于依赖于低级原语,我不确定实现是否良好.我认为,根据经验,我们应该避免使用这种低级原语.也许这是合理的情况.

也许有一个更好的选择wait()java.util.concurrent.

java multithreading future

0
推荐指数
1
解决办法
154
查看次数

理解 ANTLR4 代币

我对 ANTLR 很Token陌生,我试图了解ATNLR4 中到底是什么。考虑以下非常荒谬的语法:

grammar Tst;

init: A token=('+'|'-') B;

A: .+?;
B: .+?;
ADD: '+';
SUB: '-';
Run Code Online (Sandbox Code Playgroud)

ANTLR4 为其生成以下TstParser.InitContext内容:

public static class InitContext extends ParserRuleContext {
        public Token token;       //<---------------------------- HERE
        public TerminalNode A() { return getToken(TstParser.A, 0); }
        public TerminalNode B() { return getToken(TstParser.B, 0); }
        public InitContext(ParserRuleContext parent, int invokingState) {
            super(parent, invokingState);
        }
        @Override public int getRuleIndex() { return RULE_init; }
        @Override
        public void enterRule(ParseTreeListener listener) {
            if ( listener instanceof TstListener …
Run Code Online (Sandbox Code Playgroud)

java token lexer antlr4

0
推荐指数
1
解决办法
2703
查看次数