new to generics, need help

I know Java very well, but I'm new to generics and I guess I'm just not seeing things right. I'm trying to write a Sudoku solver, which will use constraint satisfaction to search for an answer. If you don't know about constraint satisfaction, it's like graph search where each node (called a variable) has a set of values, and the constraints are things that limit these values. The goal is to search for a value for each variable that satisfies every constraint. In this program, we'll only use binary constraints, where two variables cannot have the same value. Hence, every box will be connected with an inequality constraint to every other box in its row, column, and 3x3 region.

I'd like to keep this generic enough to work on all of the Sudoku variants. Here are the declarations of the interfaces that describe the basic CSP (constraint satisfaction problem) objects:

public interface Variable<T> (here, T is the datatype that goes in the cell. Could be Integer,Character, or anything else)

public interface BinaryConstraint<V extends Variable><T>> (this is the one giving me problems)

public interface Operator<V extends Variable> (an operator is something that compares variables with a certain operation, in this project, it will be "not equal to", but some variations also have "less than").

Here are the declarations for the classes that implement those interfaces:

public class SudokuBox<T> implements Variable<T>

public class SudokuConstraint<SudokuBox><T>> implements BinaryConstraint<SudokuBox><T>> (also giving me problems, along with the interface)

I haven't done an Operator class yet. Any help would be appreciated. If you just give me the correct declaration, that's fine, but it would be great if someone could explain things clearly to me.

[1895 byte] By [MatthewPutnama] at [2007-11-27 0:17:51]
# 1

The problems you have is due to using T without defining it. The following should do:public interface BinaryConstraint<T, V extends Variable><T>>

public class SudokuConstraint<T> implements BinaryConstraint<T, SudokuBox><T>>

Further, you should revise Operator, as it by now references a raw type Variable. I am not sure, if the design you chose is viable, as there is too few information about the use of the generic parameters.

stefan.schulza at 2007-7-11 22:07:17 > top of Java-index,Core,Core APIs...
# 2
Thanks, that did it. Revising Operator the same way also worked.
MatthewPutnama at 2007-7-11 22:07:17 > top of Java-index,Core,Core APIs...