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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:26:05+00:00 2026-05-16T02:26:05+00:00

I faced with a sample code in Java and it brought me a question.

  • 0

I faced with a sample code in Java and it brought me a question.

Java sample code is:

...
public interface CLibrary extends Library {
    CLibrary INSTANCE = (CLibrary) Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"), CLibrary.class);
    void printf(String format, Object... args);
}

public static void main(String[] args) throws IOException {
    CLibrary.INSTANCE.printf("Hello, World\n");
}

But in C# we cannot write like that:

public interface IMyInterface {
    static readonly int staticInt = 5;                          // compile error
    static readonly SomeClass staticInstance = new SomeClass(); // compile error
}

What is the difference between these two languages/frameworks?

What design policy permit java to have const fields in an interface or what prevents .NET from having that?

  • 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-16T02:26:05+00:00Added an answer on May 16, 2026 at 2:26 am

    The use of interfaces to hold constants is usually frowned on these days in Java too. (I’d say that storing non-compile-time-constant fields like your example is even more frowned upon.)

    Fundamentally, it’s at odd with the idea of an interface: a contract that the implementation will uphold. The implementation isn’t going to provide the field, so what’s it doing there?

    I suspect the C# team decided that it was sufficiently at odds with the concept behind interfaces to not include it in the language. I don’t know whether it’s just a C# restriction or a CLR restriction too. For example, I know that the CLR allows interfaces to declare nested types, but C# doesn’t currently allow this.

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

Sidebar

Related Questions

Recently I published my open source java game server code to github and faced
Issue When benchmarking a simple QuickSort implementation in Java, I faced unexpected humps in
I faced this puzzle question[ related to data structure ] in a coding competition.
I faced one issue while working on a C code with Microsoft Visual Studio-2005
I've faced with a problem of sending complex requests with GroovyWS. This is sample
Here is a sample code that I have: void test() { Object1 *obj =
Ok, so I've asked a similar question already, but I'm now faced with a
I am trying to follow the sample code on encoding in the ffmpeg document
I have an .obj parser, code is: class Model { public: List *coords; List
I'm trying to debug & extend an existing piece of Java code using BouncyCastle

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.