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 9148793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:22:03+00:00 2026-06-17T11:22:03+00:00

I don’t understand the following code: public class EventAdapter extends ArrayAdapter<Event> { public EventAdapter(Context

  • 0

I don’t understand the following code:

public class EventAdapter extends ArrayAdapter<Event> 
{
    public EventAdapter(Context context, int textViewResourceId,
            List<Event> objects) 
    {
        super(context, textViewResourceId, objects);
        this.resource = textViewResourceId;
    }
}

I am confused about the <Event> part in both cases. I understand it has something to do with Generics, but I don’t understand it. I read http://docs.oracle.com/javase/tutorial/java/generics/, but still don’t understand.

I do understand that objects is an ArrayList of objects of the type Event.

The part I don’t understand is extending an ArrayAdapter with the Type <Event>. What does this signify?

  • 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-06-17T11:22:06+00:00Added an answer on June 17, 2026 at 11:22 am

    extends ArrayAdapter<Event>

    The type restriction here will influence on the return types of methods in the class, and the argument types of methods.

    Here is an example, if you have a class:

    class SomeClass<T> {
        protected T value;
    
        public void setValue (T value) {
            this.value = value;
        }
    
        public T getValue () {
            return value;
        }
    }
    

    And if you have another class:

    class SubClass extends SomeClass {
    
        @Override
        public void setValue (Event value) {    // Fail! It is not overriding the super class' method.
            this.value = value;    // Warning! Unchecked types (maybe inconsistent).
        }
    }
    

    If you remove the @Override annotation, it will run. But the extends SomeClass is useless and might cause problem if you keep it there — there will be two very similar methods: setValue(Event) and super.setValue(T). Now the question is will the subclass have access to the super.setValue(T) method? I will explain it in the end, see “A missing type parameter bounding example”.

    So, you need to specify the type in declaration:

    class SubClass extends SomeClass<Event> {
    
        @Override
        public void setValue (Event value) {    // Correct now!
            this.value = value;
        }
    }
    

    Also, if you declare an inconsistent type:

    class SubClass extends SomeClass<String> {
    
        @Override
        public void setValue (Event value) {    // Fail! Not overriding.
            this.value = value;    // Fail! Inconsistent types.
        }
    }
    

    So the type restricts the behavior of class body.



    A missing type parameter bounding example:


    import java.lang.reflect.*;
    
    class Super<T> {
        public void method (T t) {
            System.out.println("Hello");
        }
    
        public void method2 () {
    
        }
    }
    
    public class Test extends Super {
        /*public void method (Object t) {
            System.out.println("world");
        }*/
    
        /*public <T> void method (T t) {
    
        }*/
    
        public static void main (String args[]) {
            new Test().method("");
            for (Method m : Test.class.getMethods()) {
                System.out.println(m.toGenericString());
            }
        }
    }
    
    • If I comment method() in the subclass, it is compiled with a warning: Test.java uses unchecked or unsafe opertations. In the running result, it turned the generic type T into Object: public void Test.method(java.lang.Object).

    • If I only uncomment the first method() in the subclass, it is compiled with no warnings. In the running result, the subclass owns one public void Test.method(java.lang.Object). But it doesn’t allow @Override annotation.

    • If I only uncomment the second method() in the subclass (which also has a generic type bounding), the compile fails with an error: name clash. It also doesn’t allow @Override annotation. If you do so, it throws a different error: method does not override.

    • method2() is inherited by the subclass unanimously. But you also can’t write the following code:

      in superclass: public void method2 (Object obj) and in subclass: public <T> void method2 (T obj). They are also ambiguous and is not allowed by the compiler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't understand this simple code: def main(): print (This program illustrates a chaotic function)
don't know better title for this, but here's my code. I have class user
Don't ask me how--I haven't the slightest. The following code crashes my terminal and
Don't be scared of the extensive code. The problem is general. I just provided
Don't ask me why but I need to do the following: string ClassName =
I don't know why, but this code worked for me a month ago... maybe
Don't think that I'm mad, I understand how php works! That being said. I
Don't be frightened, its a very basic code. Just wanted to check with you
Don't they both have to convert to machine code at some point to execute
Don't have much to say, just can get into the event handler. XAML: <Grid>

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.