[Biojava-dev] another 1.5 generics question

Michael Heuer heuermh at acm.org
Tue Apr 20 13:45:48 EDT 2004


All,

Sorry to abuse the list with another 1.5 generics question.

Given,

import java.util.Map;
import java.util.Set;

/**
 * A graph.
 */
public interface Graph<A, B>
{

    /**
     * Return a read-only set view of the nodes in this graph.
     */
    Set<Node<A>> nodes();

    /**
     * Return a read-only set view of the edges in this graph.
     */
    Set<Edge<B>> edges();

    /**
     * Return a map of type <code>&lt;Node, T&gt;</code> with
     * the nodes in this graph as keys.
     */
    <T> Map<Node, T> nodeMap();

    /**
     * Return a map of type <code>&lt;Edge, T&gt;</code> with
     * the edges in this graph as keys.
     */
    <T> Map<Edge, T> edgeMap();

    /**
     * Create a node in this graph for the specified element
     * (optional operation).
     */
    Node<A> createNode(A a)
        throws UnsupportedOperationException;

    /**
     * Create an edge in this graph for the specified element
     * connecting the specified set of nodes (optional operation).
     */
    Edge<B> createEdge(B b, Set<Node<A>> nodes)
        throws UnsupportedOperationException;


    /**
     * Node in a graph.
     */
    interface Node<A>
    {

        /**
         * Return the element at this node.
         */
        A get();

        /**
         * Set the element at this node to <code>a</code>
         * (optional operation).
         */
        void set(A a)
            throws UnsupportedOperationException;

        /**
         * Return a read-only set view of the edges in this graph connected
         * to this node.
         */
        Set<Edge<B>> edges();
    }


    /**
     * Edge in a graph.
     */
    interface Edge<B>
    {

        /**
         * Return the element at this edge.
         */
        B get();

        /**
         * Set the element at this edge to <code>b</code>
         * (optional operation).
         */
        void set(B b)
            throws UnsupportedOperationException;

        /**
         * Return a read-only set view of the nodes in this graph connected
         * by this edge.
         */
        Set<Node<A>> nodes();
    }
}

I get a complaint about the Set<Edge<B>> edges() method on
Node<A> and the Set<Node<A>> nodes() method on Edge<B>:

  non-static class A cannot be referenced from a static context

I'm a bit confused, because I thought that everything is static in an
interface definition, and I thought that A, B in this example are just
type placeholders for the element classes.

   michael



More information about the biojava-dev mailing list