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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:04:47+00:00 2026-06-04T12:04:47+00:00

I have a java program which uses arraylists – these arraylists store ‘variables’ where

  • 0

I have a java program which uses arraylists – these arraylists store ‘variables’ where ‘variables’ is an abstract class.

Now, to save memory, I want to use a java library called HugeCollections-VanillaJava- however this library requires an interface to be defined.

How do I convert the abstract class into an interface? What rules/restrictions do I have to follow, to correctly perform the conversion?

Finally, is it possible for me to use my abstract class with minimal code changes, so that the library that requires an interface, also works correctly? Ideally I would like not to change the abstract class at all…Is this possible?

  • 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-04T12:04:49+00:00Added an answer on June 4, 2026 at 12:04 pm

    how do I convert an abstract class into an interface?

    1. Make a copy of the abstract class source file.

    2. Change “class” to “interface” in the initial declaration.

    3. Change the name (optionally, depends on what you’re doing).

    4. Remove the bodies of any methods that are implemented by the class.

    5. Remove the word “abstract” from the other ones.

    6. Remove all private and protected members.

    7. Remove all constructors.

    8. Remove the keyword “public” from the public members.

    If you had any code you removed (implemented methods, private or protected stuff), have your original abstract class implement your interface and leave that stuff there.

    (Incomplete) Example:

    Foo as an abstract class:

    public abstact class Foo
    {
        private int bar;
    
        public static final int SOME_CONSTANT = 42;
    
        public Foo(b) {
            this.bar = b;
        }
    
        public abstract void doSomething(String s);
    
        protected int doSomethingElse() {
            return this.bar * 2;
        }
    }
    

    Foo as an interface:

    public interface Foo
    {
        int SOME_CONSTANT = 42;
    
        void doSomething(String s);
    }
    

    In my case, as I did have some stuff the old Foo did, I’d probably have AbstractFoo or something:

    public abstact class AbstractFoo implements Foo
    {
        private int bar;
    
        public Foo(b) {
            this.bar = b;
        }
    
        public abstract void doSomething(String s);
    
        protected int doSomethingElse() {
            return this.bar * 2;
        }
    }
    

    …so that an implementation could use it as a starting point if desired (although with that private bar in there, it doesn’t make a lot of sense).

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

Sidebar

Related Questions

I have a program which uses the Robot class in Java to automate a
I have avery simple program which uses MediaPLayer. I am new to java and
I now have a running Java program which only lacks of the final step,that
I have developed a Java Swing application, which uses the SwingWorker class to perform
I have a Java program which uses a lot of text files. The program
I have a Java program which its main method (in the main class) expects
I have a web app in Java, which uses some external program (invokes a
I have a Java program which is using WMIC to get certain information about
I have a java program which sends a udp packet to a server when
I have a Java program which prepares data into a fairly complex and big

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.