Type of casting through composition (interfaces and classes)

I have a serious disconnect when I try to use class methods (of which both classes implement interfaces) that also contain generics. I have an interface SetInterfacethat contains methods for my class Set. The same is true for my interface ProfileInterfaceand class Profile. In my class Profile, I have the following listing type related to the class Set:

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

We mainly study Array Bags, Linked Bagsetc. in my Data Structures class. My problem is that I want to use the methods of the SetData Structure class in the class Profilethrough Composition. The only problem I am facing is that I need to create a method in my class Profilethat cross-references the elements in the given array to see if this object is Profile“next” different Profileand, if not, recommends that the object performed (the purpose is to perform something similar to that of Twitter or Facebook with a Data Structure). Here is the method that I have created so far, and the error I cannot get (third line above):

    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 match, do nothing
            //if Profile do not match, set recommended == the Profile
        }
    }
    return recommended;
}

, , , . , , , , ( ).

Java, . , 5- , . , Profile "" (Composition) Set. , , followBag , ProfileInterface Set. , , , Set ? (thisProfile ) . , :

A) , : ProfileInterface thisProfile = new Profile();

, , ? , Profile(), thisProfile; ?

B) ProfileInterface thisProfile, thisProfile for?

C) : IntelliJ , "cannot resolve method getCurrentSize()". , follows . , ProfileInterface follows = followBag[index] Profile , , . . , ​​ , , , .

, !

+4
1

A) , : ProfileInterface thisProfile = new Profile();

-, , -.

, , ? , Profile(), ; ?

ProfileInterface. , ProfileInterface Profile. .

C) : IntelliJ, , " getCurrentSize()". , .

, followBag Set getCurrentSize().

, ProfileInterface = followBag [index] , , .

C. followBag . , , #, Java . [] . get() .

, B. , , - , , .

0

Source: https://habr.com/ru/post/1627536/


All Articles