小编Jes*_*sse的帖子

用于SQL数据定义语言的Java API

在我编写之前,是否有用于操作数据库的Java API.就像一个面向对象的包装器java.sql.DatabaseMetaData,支持类似的东西Schema.createTable(name, columns)

显然,正确的SQL语句应该在后台基于正在使用的DB执行.

我对用于执行DDL语句的API特别感兴趣.

java sql database ddl

10
推荐指数
1
解决办法
2481
查看次数

Java自身类型递归类型参数和javac中的继承错误

为什么这段代码不能编译?

public class x
{
    private void test()
    {
        handle(new ThingA());
        handle(new ModifiedThingA());
    }

    private <T extends BaseThing<T>, X extends T> java.util.List<T> handle(X object)
    {
        return object.getList();
    }

    private static class BaseThing<T extends BaseThing<T>>
    {
        public java.util.List<T> getList()
        {
            return null;
        }
    }

    private static class ThingA
        extends BaseThing<ThingA>
    {
    }

    private static class ModifiedThingA
        extends ThingA
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

Java 6在handle(new ModifiedThingA());以下版本中给出了此错误:

x.java:6: <T,X>handle(X) in x cannot be applied to (x.ModifiedThingA)
            handle(new ModifiedThingA());
            ^
Run Code Online (Sandbox Code Playgroud)

Java 7甚至不喜欢handle(new …

java generics javac java-6 java-7

8
推荐指数
1
解决办法
1832
查看次数

Java泛型与递归类型参数绑定

我有一个基类Thing,它提供了一些基本功能,包括ThingInfo使用类的类型参数获取对a的引用Thing.因为Java没有自我类型,所以我不能将它用于ThingInfo返回值的类型参数,所以Thing必须采用递归类型参数来允许我们返回正确的参数化ThingInfo.

interface ThingInfo<T>
{
    // just an example method showing that ThingInfo needs to know about
    // the type parameter T
    T getThing();
}

class Thing<T extends Thing<T>>
{
    // I need to be able to return a ThingInfo with the type parameter
    // of the sub class of Thing. ie. ThingA.getThingInfo() must return
    // a ThingInfo<ThingA>.
    // This is where Java would benefit from self types, as …
Run Code Online (Sandbox Code Playgroud)

java generics javac java-7

6
推荐指数
1
解决办法
1545
查看次数

Java是否保证当前同步的对象不会被垃圾回收?

是否可以保证在线程持有其监视器时不会对对象进行垃圾回收?

例如

class x {
    private WeakReference<Object> r;

    Object getMonitorObject() {
        Object o = new Object();
        r = new WeakReference<>(o);
        return o;
    }

    void thread1() throws Exception {
        synchronized (getMonitorObject()) {
            Thread.sleep(3000);
        }
    }

    void thread2() {
        Object b = r.get();
    }
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,是否有任何保证在另一个线程正在休眠时b被非nullif thread2()调用thread1()?让我们假设整个过程thread2()thread1()在另一个线程中休眠时执行的。

java garbage-collection java-memory-model

5
推荐指数
1
解决办法
90
查看次数

将方法调用委托给同一接口的集合的接口实现的正确术语是什么?

我有一个界面:

public interface Doer
{
    public void do(Object arg);
}
Run Code Online (Sandbox Code Playgroud)

我有一个实现,它保存一个列表Doers,并在每个上执行任何操作:

public class DoerCollectionThing
    implements Doer
{
    private List<Doer> doers....

    public void addDoer(Doer d)
    {
        doers.add(d);
    }

    public void do(Object arg)
    {
        for (Doer d : doers){
            d.do(arg);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

那么,我该怎么称呼DoerCollectionThing?是一个DoerAggregator吗?或许DoerCollectionDoer?你们都用这种东西做什么?

java

4
推荐指数
1
解决办法
119
查看次数