#How can I use T as dynamic and pass two different packages?

7 messages · Page 1 of 1 (latest)

lime eagle
#

Hi I have a file called populator

public <T extends DataStructure> void populateFromComposition(T dataStructure, Composition input) {

But then I have a file called,

a84 which has package a084
and antoher file called a115 with package a115

And I want to use this populator in both the files, but I need to somehow passdown the package so it can be dynamic
DataStructure dataStructure115 = new DataStructure();
ppsMetaPopulator.populateFromComposition(dataStructure115 ,input)

In a115 file

DataStructure dataStructure84 = new DataStructure();
ppsMetaPopulator.populateFromComposition(dataStructure84 ,input);
in a84 file

is this possible somehow? Because this doesnt work,

this <T extends DataStructure> DataStructre are red and need a package it says.

signal violetBOT
#

This post has been reserved for your question.

Hey @lime eagle! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

slate pebble
#

is that generic even useful

#

you haven't imported DataStructure apparently

lime eagle
frozen mango
#

Are you saying that you have a DataStructure class in package a115 and another DataStructure class in package a84?
In which case:

  • say that, don't say something else
  • generics can't help you. That's not what they're for
  • do not have that. Change your design