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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:42:23+00:00 2026-06-12T11:42:23+00:00

This is something that I was wondering how to do, but could not find

  • 0

This is something that I was wondering how to do, but could not find a way that suits the problem.

Suppose I have a class that could serve two purposes: Upload and Download. Instinctively, I would create an object somewhat like this:

public class File{
 private FormFile uploadFile;
 private File downloadFile;
 private String uploadLocation;
 private String downloadLocation;

 //setters and getters
}

The thing is, I would want to have only one set of accessors for each type. For example, there is only one setFile(Object obj) in the class. But this would cause a problem because FormFile and File are two distinct objects.

I would then resort for OOP. Change my object to:

public interface File{
 public void setFile(Object obj);
 public Object getFile();
 public void setLocation;
 public String getLocation;
}

Then create the two other objects:

public UploadFile implements File{
 private FormFile file;
 private String location;

 //implementation of methods
}

public Download implements File{
 private File file;
 private String location;

 //implementation of methods
}

This could work if you clean other things within the code. But I realized that this would be harder to maintain afterwards. Is there another workaround to do this?

Something like:

File file = new File.UPLOAD;

would restrict the user to:

Use only method setFile(FileForm file){ }, and then setFile(File file){ } would become unavailable. Works vice versa when instantiating File file = new File.DOWNLOAD

I’m not really trying to solve anything on this. Just a thought.

  • 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-12T11:42:24+00:00Added an answer on June 12, 2026 at 11:42 am

    Try with generics:

    public class File < T > {
    
        private T file;
        private String location;
    
        public T getFile() {
            return file;
        }
        public void setFile( T file ) {
            this.file = file;
        }
    
        public String getLocation() {
            return location;
        }
        public void setLocation( String location ) {
            this.location = location;
        }
    
    }
    

    Usage:

    File< FormFile > uploadFile = new File< FormFile >();
    uploadFile.setFile( new FormFile() );
    
    File< java.io.File > downloadFile = new File< java.io.File >();
    downloadFile.setFile( new java.io.File( "something.txt" ) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So this is something that I have not been able to find any documentation
I have in mind a design problem that does not look like complex, but
I am wondering how you would approach this problem I have two Taxrates that
This is something that I solved using reflection, but would like to see how
this is something that i don't want to program, but i was looking for
This is something that I have had trouble with in the past and it's
This is something that I'm sure I should know the answer to, but either
Perhaps I'm overlooking something obvious but I was wondering what the fastest way to
I did do some googling and searching on this site but did not find
I'm wondering if its possible to have a property/field in a class that is

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.