2011-11-11 15 views
1

クラス階層にいくつかの追加レイヤーを追加するまで、私はいくつかのクラスにユーザーJavaジェネリックスとすべてがうまくいきました。Java genericsと "Bound mismatch"

問題が「タイプ消去」に関連しているのだろうと思っていますが、これを排除するために継承を表現する方法がわかりません。

クラス定義:

public interface IBaseDAO <T, PK extends Serializable>; 
public interface IEntityDAO<T extends BaseEntity> extends IBaseDAO<T, Integer>; 
public interface IBaseFileDAO<T extends File> extends IEntityDAO<T>; 
public interface IInvoiceDAO extends IBaseFileDAO<Invoice>; 

public class BaseDAO<T, PK extends Serializable> implements IBaseDAO<T, PK>; 
public abstract class EntityDAO<T extends BaseEntity> extends BaseDAO<T, Integer> implements IEntityDAO<T>; 
public abstract class BaseFileDAO<T extends File> extends EntityDAO<T> implements IBaseFileDAO<T>; 
public class InvoiceDAO extends BaseFileDAO<Invoice> implements IInvoiceDAO; 

public abstract class BaseEntity implements Serializable; 
public class File extends BaseEntity; 
public abstract class Transaction extends File; 
public class Request extends Transaction; 
public class Invoice extends Request; 

エラーは以下のとおりです。

Bound mismatch: The type Invoice is not a valid substitute for the bounded parameter <T extends File> of the type BaseFileDAO<T> 
Bound mismatch: The type Invoice is not a valid substitute for the bounded parameter <T extends File> of the type IBaseFileDAO<T> 

私は誰もが私に排除するためにInvoiceクラスを表現する方法についていくつかのアドバイスを与えることができ、ここで少し私の深さの外にしていますエラー?

EDITは:このことができますが、私も持っている場合

わからない:私はあなたがアップあなたの質問を台無しにしたと思う

public class FileDAO extends BaseFileDAO<File> implements IFileDAO; 
public interface IFileDAO extends IBaseFileDAO<File>; 
+4

この問題が発生するには、13個のクラス/インターフェイスが必要です。最小限の例を作って読みやすいようにしてください。 –

+0

'java.io.File'と競合していませんか? –

+0

これは 'IEntityDAO 'と 'EntityDAO 'でなければなりません。 – gigadot

答えて

0

...これは私のためにコンパイルされます。

import java.io.Serializable; 

interface IBaseDAO <T, PK extends Serializable> { } 
interface IEntityDAO<T extends BaseEntity> extends IBaseDAO<T, Integer> { } 
interface IBaseFileDAO<T extends File> extends IEntityDAO<T> { } 
interface IInvoiceDAO extends IBaseFileDAO<Invoice> { } 

class BaseDAO<T, PK extends Serializable> implements IBaseDAO<T, PK> { } 
abstract class EntityDAO<T extends BaseEntity> extends BaseDAO<T, Integer> implements IEntityDAO<T> { } 
abstract class BaseFileDAO<T extends File> extends EntityDAO<T> implements IBaseFileDAO<T> { } 
class InvoiceDAO extends BaseFileDAO<Invoice> implements IInvoiceDAO { } 

abstract class BaseEntity implements Serializable { } 
class File extends BaseEntity { } 
abstract class Transaction extends File { } 
class Request extends Transaction { } 
class Invoice extends Request { } 

ここでは、タイプ消去とは関係ありません。

+0

私はちょうどあなたが提案したコードでEclipseで新しいプロジェクトを作成しました。あなたはserialVersionUIDについてのわずかな警告でコンパイルするのは間違いありません! – hairyone