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

  • Home
  • SEARCH
  • 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 8910647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:44:33+00:00 2026-06-15T03:44:33+00:00

I feel like I should know this, but can’t really explain it when asked.

  • 0

I feel like I should know this, but can’t really explain it when asked.
I have a method:

public <T extends IByteConverter<T>> int write(T obj) throws IOException {
    byte[] byteArray = obj.toByteArray();
    raFile.write(byteArray);
    //keeps track of size of what was written
    return byteArray.length;
}

and my interface:

interface IByteConverter<T> {
    public byte[] toByteArray();
    public T fromByteArray(byte[] byteArray);
}

When I call obj.toByteArray(), How does my program know what to do? No where in my class do I actually implement the code in IByteConverter, but the program works just as expected. Is there a simple way to explain what is going on?

  • 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-15T03:44:34+00:00Added an answer on June 15, 2026 at 3:44 am

    Let’s make the thing easier to understand with another example : you define an interface Fruit, which has a method getColor(). The contract of this method is that it returns a color.

    Based on this contract, you define a class that takes an array of Fruits, and counts the number of red ones.

    You don’t need any implementation for this method to compile, because you can be sure that the only thing that can be passed to this method is an array of objects, which are instances of a class that indeed implements the Fruit interface. In order for this method to be run, you’ll need to define at least one class that implements the Fruit interface (like Apple for example), and to construct an array of objects of this class.

    That’s what polymorphism is all about: you can call a method of an object without knowing what its actual class is, provided it respects the contract of its interface.

    Generics don’t make this different. Since obj is of type T, and since T extends IByteConverter, you can call the toByteArray() method on obj.

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

Sidebar

Related Questions

I feel like this should have a simple answer, but I can't find it.
I feel like this is something I should already know, but I'm just not
I feel like I should know this but I've been stumped for hours now
I feel like I should know this, but I haven't been able to figure
I feel like this question ought to have been covered, but I can't seem
I feel like this should be really really simple, but I'm completely stuck! In
I feel like this should be an easy question, but I can't get it
I feel like this should be an easy question but I can't seem to
I feel like this should be a no brainer, but clearly I'm missing something...
I feel like this should be obvious to me, but for some reason I

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.