小编Ang*_*nyu的帖子

如何在Java中组合Closeable对象?

我正在尝试创建一个管理多个Closeable资源的Java类.C++解决方案可以直接使用大量资源轻松扩展:

class composed_resource
{
    resource_a a;
    resource_b b;
    resource_c c;

    composed_resource(int x)
        : a(x), b(x), c(x)
    { }

    ~composed_resource()
    { }
};
Run Code Online (Sandbox Code Playgroud)

我天真的Java解决方案:

public class ComposedResource implements Closeable
{
    private final ResourceA a;
    private final ResourceB b;
    private final ResourceC c;

    public ComposedResource(int x) /* throws ... */ {
        a = new ResourceA(x);
        try {
            b = new ResourceB(x);
            try {
                c = new ResourceC(x);
            } catch (Throwable t) {
                b.close();
                throw t;
            }
        } catch (Throwable t) …
Run Code Online (Sandbox Code Playgroud)

java

11
推荐指数
1
解决办法
769
查看次数

为什么Hugs在我的数据类型声明中抱怨`|`?

我正在使用haskell编写一个小的lisp解释器.在此过程中,我定义了此数据类型,以获得较少类型的数字.

data Number = _Int Integer
            | _Rational Rational
            | _Float Double
    deriving(Eq,Show)
Run Code Online (Sandbox Code Playgroud)

用拥抱编译它失败,出现以下错误:

错误"types.hs":16 - 数据类型声明中的语法错误(意外的"|")

第16行是|上面代码中第一行的行.

haskell hugs

3
推荐指数
1
解决办法
387
查看次数

标签 统计

haskell ×1

hugs ×1

java ×1