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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:31:34+00:00 2026-05-26T03:31:34+00:00

Notice: This question is obsolete; the interface declaration syntax has been removed from Dart:

  • 0

Notice: This question is obsolete; the interface declaration syntax has been removed from Dart:

  • Proposal to eliminate interface declarations from Dart

    “In Dart, every class engenders an implicit interface. Now that this feature is implemented, it is possible to actually eliminate interface declarations from the language. Interface declarations are replaced by purely abstract classes.”

  • Issue 3972: Remove interface declaration support in VM


As far as I’ve been able to tell, it’s impossible to instantiate an interface in Dart. If I simply try to construct a new MyInterface(), with or without a constructor defined, I get a run-time error (try it):

NoSuchMethodException - receiver: '' function name: 'MyInterface$$Factory' arguments: []]
interface MyInterface {}      
interface MyInterface {
  MyInterface();
}

If I try to use a factory constructor instead, returning an instance of an implementation, I get a compile-time error (try it):

SyntaxError: factory members are not allowed in interfaces
class MyImplementation implements MyInterface {
  MyImplementation();
 }

interface MyInterface {
  factory MyInterface() { return new MyImplementation(); }
}

However, this seems at-odds with the reality that List<E>1 in Dart’s core library is an interface2, yet it has several constructors and can be instantiated. For example, this works fine (try it):

main() {
  var list = new List();
  list.add(5);
  print(list.last());
}

Why can List and many other built-in interfaces be instantiated? Is there some method I missed or are they just receiving special treatment as built-in types?


1 Dart: Libraries: corelib: interface List<E>
2 “Much of the Dart Core Library is defined in terms of interfaces.”3
3 Dart: Tutorial: Interfaces

  • 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-26T03:31:35+00:00Added an answer on May 26, 2026 at 3:31 am

    The syntax for defining an interface is:

    interfaceDefinition:
        interface identifier typeParameters? superinterfaces? factorySpecification? `{' (interfaceMemberDefinition)* `}'
    

    Notice that the factorySpecification must come before the body of the interface rather than inside it.

    So this is how you write it:

    interface MyInterface default MyImplementation {
    
    }
    
    class MyImplementation implements MyInterface {
      MyImplementation();
    }
    

    Or if you want to go for the full generic definition:

    interface MyInterface<E> default MyImplementation<E> {
        MyInterface(x);
    }
    
    class MyImplementation<E> implements MyInterface<E> {
      MyImplementation(this.x);
      E x;
    }
    

    Edit: For a more complete example, you can read the source code for the interface List<E> at https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/corelib/src/list.dart and the associated class ListFactory<T> source is at https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/runtime/lib/array.dart

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

Sidebar

Related Questions

I notice this question has been asked a few times but I don't really
As some of you may notice this question is problem 16 from Project Euler
This question comes to you from someone who's been burned by SVN before and
I know this question has been asked many times and we have gotten this
This question has been asked here before, but the author wasn't very clear and
This question has been asked before - but with no satisfying answer at all!
Update: this question has been answered (see below). I'll leave it up in case
As you come to this question you'll notice the title of the question is
Sorry if this question is not programmatic enough, but it has significant implications to
NOTICE This is a rather large question, so please bear with me and I

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.