Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 889913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:38:32+00:00 2026-05-15T13:38:32+00:00

I have instantiated an object like this: GraphMatrixDirected<String, Integer> g g is passed to

  • 0

I have instantiated an object like this:

GraphMatrixDirected<String, Integer> g

g is passed to a function like this:

floyd(g);

floyd’s signature looks like this:

public void floyd(GraphMatrixDirected<V,E> g) 

Eclipse gives me an error saying:

The method floyd(GraphMatrixDirected<V,E>) in the type GraphMatrix<V,E> is not applicable for the arguments (GraphMatrixDirected<String,Integer>)

What do I need to do to fix it?

Edit1:

abstract public class GraphMatrix<V,E> extends AbstractStructure<V> implements Graph<V,E>

Edit2:

public interface Graph<V,E> extends Structure<V>

public abstract class AbstractStructure<E> implements Structure<E>

public interface Structure<E> extends Iterable<E>
/* JDT added extension of Iterable for Java 5 */

Edit 3:
Note: Funtion was changed from floyd to AllPairsShortestPath.

public void AllPairsShortestPath(GraphMatrixDirected<V,E> g) 
// post: g contains edge (a,b) if there is a path from a to b 
{
    Iterator<V> witer = g.iterator();
    while (witer.hasNext()) 
    {
        Iterator<V> uiter = g.iterator();
        V w = witer.next(); 

        while (uiter.hasNext())
        {
            Iterator<V> viter = g.iterator(); 
            V u = uiter.next(); 

            while (viter.hasNext()) 
            {
                V v = viter.next(); 

                if (g.containsEdge(u,w) && g.containsEdge(w,v)) 
                {
                    Edge<V,E> leg1 = g.getEdge(u,w);
                    Edge<V,E> leg2 = g.getEdge(w,v); 

                    Integer leg1Dist = (Integer)leg1.label(); 
                    Integer leg2Dist = (Integer)leg2.label(); 
                    Integer newDist = (Integer)leg1Dist+leg2Dist;

                    E newDistE = (E)newDist;

                    if (g.containsEdge(u,v)) 
                    {
                        Edge<V,E> across = g.getEdge(u,v);
                        Integer acrossDist = (Integer)across.label(); 

                        if (newDist < acrossDist)
                        {
                            across.setLabel(newDistE);
                        } 
                    } 
                    else 
                    {
                        g.addEdge(u,v,newDistE);
                    }
                }
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:38:33+00:00Added an answer on May 15, 2026 at 1:38 pm

    Perhaps you meant floyd to be a generic method?

    public <V,E> void floyd(GraphMatrixDirected<V,E> g)
    

    Otherwise, whatever generic type floyd is a member of need to have <V,E> parameterized as <String,Integer>.

    If it’s true that floyd belongs to a generic type, and yet floyd also needs to be a generic method with its own type parameters, you may want to choose different names, so as not to hide one another.

    References

    • Java Tutorials/Generics
    • Angelika Langer’s Java Generic FAQs
      • Generic Types and Generic Methods

    On generic type vs generic methods

    The choice between which solution route to take depends on what floyd does and other things. One essential question is this: do you consider floyd to be a method that belongs specifically to the generic type GraphMatrixDirected<V,E> (answer is probably no) or is it rather a generic utility method that works with any Graph<V,E>? (answer is probably yes).

    For example and guidance, we can also take a look at how Java Collections Framework is structured:

    • interface List<E> – a generic type that defines basic functionality for the type
      • specifies boolean add(E e), E get(int index), etc
    • class Collections – provides static utility generic methods
      • static void shuffle(List<?> list)
      • static <T extends Comparable<? super T>> void sort(List<T> list)
      • static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll)

    Assuming that floyd is indeed an implementation of Floyd-Warshall all-pairs shortest path algorithm, I’d argue that it should be a static utility method to say a Graphs class, and works with any Graph<V,E>.

    See also, Effective Java 2nd Edition

    Generic types vs methods:

    • Item 26, Favor generic types
    • Item 27, Favor generic methods

    Interfaces:

    • Item 18, Prefer interfaces to abstract classes
    • Item 19, Use interfaces only to define types
    • Item 52, Refer to objects by their interfaces
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 450k
  • Answers 450k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The Django QuerySet docs are very clear on this: get(**kwargs)¶… May 15, 2026 at 8:24 pm
  • Editorial Team
    Editorial Team added an answer For example: $contry.closest('tr').next('tr').find('> td > .province-select') May 15, 2026 at 8:24 pm
  • Editorial Team
    Editorial Team added an answer Try OpenInviter. May 15, 2026 at 8:24 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.