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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:30:52+00:00 2026-06-14T21:30:52+00:00

Integer[] intArray = new Integer[] {1,2,3,4}; Haha.sort(intArray); public class Haha<E extends Comparable<? super E>>

  • 0
Integer[] intArray = new Integer[] {1,2,3,4};
Haha.sort(intArray);


public class Haha<E extends Comparable<? super E>> implements B<E>
{
     private E[] array;

     public Haha()
     {
         array = (E[]) new Comparable[10];
     }

     private Haha( ??? )  
     {
         ???
     }


    public static <T extends Comparable<? super T>> void sort (T[] a)
    {
        Haha(a);
    }
}

I want to define a private constructor static sort() method can call to create a Haha object initialized with a particular given array.

But it has to sort its argument array without allocating another array because public constructor is already allocating another array.

problem 1)
How can private Haha receive ‘a’ from sort() method??
If I do

private Haha(E[] b)  // gives error because of different type   T & E
{
    // skip    
}

If I do

private Haha(T[] b) // gives error too because Haha is class of Haha<E>
{
   // skip
}

problem 2)
How to initialize object with a particular given array

private Haha( ??? b )  // if  problem 1 is solved
{
     array = b; // is this right way of initializing array, not allocating?
                // It also gives error because sort() is static, but Haha is not.

} 
  • 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-14T21:30:53+00:00Added an answer on June 14, 2026 at 9:30 pm

    I question the overall design of this class, as it seems to me the assignment is simply to sort an array in place. However, note that the generic parameter type specified in your static method is entirely different from the one defined in your class signature. You can use both:

    public class Haha<E extends Comparable<? super E>> {
        public static <T extends Comparable<? super T>> void sort (T[] a) {
            // unusual, but can be done
            final Haha<T> haha = new Haha<T>(a);
        }
    
        private E[] array;
    
        public Haha() {
            this(new Comparable[10];
        }
    
        public Haha(final E[] array) {
            super();
            this.array = array;
        }
    }
    

    But for this to work, you need to make your alternate constructor public. This is because you are trying to access it from a static method, which is effectively the same as trying to access it from an entirely different class.

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

Sidebar

Related Questions

public abstract class Main implements Comparable { public static void main(String[] args) { Integer[]
class main{ public static void main(String[] args){ int[] array = new int[3]; array[0]=3; array[1]=2;
Suppose this code: public class Test{ public static void main(String[] args) { Test.testInt(new int[]{2,3});
In Java, I have: Set<Integer> set = new HashSet<Integer>(); callVoidMethod(set); ... public static void
static void LasVegas(int []tablero, int f, int ultimaReina){ HashSet<Integer> enterosUsados = new HashSet<Integer>(); if
i have an array of integer like int [] intArray; intArray = new int[3]
import java.util.ArrayList; import java.util.Random; public class Generator{ //9352141NTBG1223 public static void main(String[] args) {
I have been trying to implement Bubble Sort using simple integer array in java.
I am trying to create a new integer array which is derived from a
Integer c=0; DatabaseHelper dbh1 = new DatabaseHelper(this); Cursor ca = dbh1.getReadableDatabase().query(DatabaseHelper.TABLE_NAME, null, null, null,

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.