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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:02:34+00:00 2026-05-28T04:02:34+00:00

To reduce dependece of class, I want to send parameter (using generic class) to

  • 0

To reduce dependece of class, I want to send parameter (using generic class) to constructor that extends some class and implements interface, for example

public interface SomeInterface{
    public void someMethod();
}

public class MyFragment extends Fragment implements SomeInterface{
    //implementation
}

//here is classs, that I need to create. T must extend Fragment and implements 
//SomeInterface. But, I'm afraid, if I'll use MyFragment directly, it will create a
//dependence of SomeClass from MyFragment.

public class SomeClass /*generic?*/ {
    public SomeClass(T parent);
}

Is it possible?

Futher, using my T class, I want to create views, using T.getActivity() as Context.

  • 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-28T04:02:35+00:00Added an answer on May 28, 2026 at 4:02 am

    T must extend Fragment and implement SomeInterface

    In that case you could declare SomeClass as the following:

    public class SomeClass<T extends Fragment & SomeInterface>
    

    That would require an object of type T to both extend Fragment and implement SomeInterface.

    Further, using my T class, I want to create views, using T.getActivity() as Context.

    I’m unfamiliar with Android, but if getActivity() is a public instance method declared in Fragment then will be entirely possible to call it on an instance of T, since the compiler will know all Ts must inherit that method.

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

Sidebar

Related Questions

I know about map/reduce alghoritm and its use. It's using functions that are called
currently i have a project using solr,now i want to add some feature,so i'm
Map Reduce is a pattern that seems to get a lot of traction lately
I am trying to reduce some code here. I will explain how I have
This should reduce the executable size quite a bit in some of my very
I'm using the minijar-maven-plugin to reduce the size of my jar-with-dependencies jar but I
I am trying to reduce ceremony and out of academic curiosity I want to
I'm designing a re-usable class library that contains 2 assemblies (amongst others) named core.xml.dll
I'd like to reduce the default font size for a buffer using Emacs lisp.
I my framework I have some functions that when done they can add some

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.