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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:25:00+00:00 2026-05-14T08:25:00+00:00

recently I’m writing some functions that I take from Haskell and translate into Java.

  • 0

recently I’m writing some functions that I take from Haskell and translate into Java.
One of the main problems I have is I cannot easily create a static property with a generic type. Let me explain by a little example…

// An interface to implement functions
public interface Func<P, R> {
    public R apply(P p);
}

// What I want to do... (incorrect in Java)
public class ... {
    public static <T> Func<T, T> identity = new Func<T, T>() {
        public T apply(T p) { return p; }
    }
}

// What I do right now
public class ... {
    private static Func<Object, Object> identity = new Func<Object, Object>() {
        public Object apply(Object p) { return p; }
    }
    @SuppressWarnings("unchecked")
    public static <T> Func<T, T> getIdentity() {
        return (Func<T, T>)identity;
    }
}

Are there any easier ways to do something like that?
What kind of problems might arise if the syntax I used would be valid?

  • 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-05-14T08:25:00+00:00Added an answer on May 14, 2026 at 8:25 am

    Just create a new tiny little object each time, for some definition of “each time”. Remember that allocations on typical JREs are tiny, but GCing static data is expensive.

    Whilst I think your syntax could be made to work without compatibility issues, it would be add complexity and irregularity whilst not bringing a huge amount on benefit.

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

Sidebar

Related Questions

Recently, I was writing a class in which I discovered that I could reduce
Recently I'm doing some work on RTMP streaming, that is using Flowplayer to integrate
Recently I have been told that static class/methods are evil. Take for example my
Recently I ran into this error in my web application: java.lang.OutOfMemoryError: PermGen space It's
Recently there was some upgrade happened from frame work 2.0 to 4.0, so after
recently I am reading about Thinking in Java. that code in my PC is
Recently one of our app servers went down, when it was rebooted the Python
Recently I have released my app into the US AppStore. Now I Planed for
Recently, I was asked to compile some of my Android projects, based on the
Recently I've noticed that on occasion I do not get a mayorship notification when

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.