Java – type conversion via composition (interfaces and classes)

When I try to use methods that contain generic classes, two of which implement interfaces, I have a major disconnect I have a setinterface interface that contains the methods of my set class The same is true of my profileinterface interface and profile class In my profile class, I have the following type conversion references set class:

private Set<ProfileInterface> followBag = new Set<ProfileInterface>();

Basically, we are learning array bags and linked bags in the data structures class My problem is that I want to use the method of set data structure class through composition in my profile class One problem I encounter is that I need to create a method in my profile class, which cross references the items in a given array to see whether the profile object "follows" another profile. If not, it is recommended to follow the object (the task is to complete tasks similar to Twitter or Facebook through the data structure) This is the method I've created so far and the error I can't pass (the third line from the top):

public ProfileInterface recommend(){
    ProfileInterface recommended;
    ProfileInterface thisProfile = new Profile(); //  <--Here is the question
    for(int index = 0; index < followBag.getCurrentSize(); index++){
        ProfileInterface follows = followBag[index];
        for(int followedFollowers = 0; followedFollowers < follows.getCurrentSize(); followedFollowers++) { // <--Question here also
            //if Profile's match,do nothing
            //if Profile's do not match,set recommended == the Profile
        }
    }
    return recommended;
}

Please forgive my pseudo code, because I'm still trying But I can't continue to use this method until I fully understand what I need to do to make the third actor correct and understand whether my other concerns (the second note) are feasible

I'm the second kind of Java, and I can't seem to pass these problems Ideally, I want one or more members to stupidly lower their age to 5 so that I can fully master it I know that the profile class has a "have a" relationship with my set class I also know that because I input my followbag in my way, it will have both profileinterface and set methods However, if possible, I want to use some examples to explain how to correctly enter the item of an array in a method, or in my set in this example and convert it to a given object? I want to populate this object (in this case thisprofile) into the given index for comparison But I need to clarify two things:

A) What happens to the object of type conversion is as follows: profileinterface thisprofile = new profile();

Since I mean the interface and the class that implements it? This means that if there are more methods in my profile () class, which methods can only be accessed by this profile; Interface or class?

B) Should I simply call profileinterface thisprofile and assign a reference to this profile to a specific index in my internal for loop?

C) My second comment: I encountered an error in IntelliJ declaring that it "cannot resolve method getcurrentsize()" I don't understand because I created a line above I think profileinterface follow = followbag [index] will set the given array index equal to the index used later in my code This mistake stems from my confusion above So, once I provide some clarity about what I did wrong, I am sure, and I believe I will solve it appropriately

Thank you. As always, I look forward to your reply!

Solution

First, this is a job, not a type conversion

You can only access methods in the profileinterface If this is a problem, I suggest you just change the profileinterface to profile There should be no problem refactoring the types of private variables

This means that followbag is a set and does not implement a method called getcurrentsize()

This has nothing to do with the first part of question C Followbag is not an array I'm not sure what you're trying to do here, but if you're a c# programmer, Java won't use the same syntax [] cannot be used to access members of the collection You must use get () or related methods

I'm really not sure what you want to say in question B I'll get rid of grammar mistakes and ask again. There are some things here that I can't know exactly where you're going

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>