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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:50:58+00:00 2026-06-11T22:50:58+00:00

Is it possible to automatically initialize fields from a parent class in the constructor?

  • 0

Is it possible to automatically initialize fields from a parent class in the constructor?

I get the syntax error:

Could not match parameter initializer ‘this.name’ with any field

class Type {
     String name;  
}

class Language extends Type {
     String id;
     Language(this.name) {
  • 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-11T22:50:59+00:00Added an answer on June 11, 2026 at 10:50 pm

    While your case is common, at this time the dart language spec specifically says:

    Executing an initializing formal this.id causes the field id of the immediately surrounding class to be assigned the value of the corresponding actual parameter.

    This essentially tells us that this.variable notation, in the constructor arguments, will only work on variables in the immediate class and not any parent classes. There are a couple of solutions available: The first is to assign it within the constructor’s body:

    class Type {
      String name;
    }
    
    class Language extends Type {
      String id;
      Language(name) {
        this.name = name;
      }
    }
    

    Alternatively, if we can change the parent class to have a constructor which will initialize the variable then we can use the initializer list in the child class:

    class Type {
      String name;
      Type();
      Type.withName(this.name);
    }
    
    class Language extends Type {
      String id;
      Language(name) : super.withName(name);
    }
    

    This is assuming there’s some reason that the default constructor for Type doesn’t automatically initialize name so we created the 2nd named constructor instead.

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

Sidebar

Related Questions

Is it possible to automatically create Word documents which include list fields from a
Is it possible to automatically return from a function using a Breakpoint/Tracepoint? I don't
Is it possible to automatically detect whether or not the page is accessed via
Based on a project is it possible to automatically generate a class diagram with
Possible Duplicate: Automatically Deploy From GitHub To Server On Push is there a way
Question: Is it possible to (automatically) change the base class of auto-generated domain objects
@selector(updateStuff:) This is automatically sends the parameter :(id)sender. Is it possible to override this
Is it somehow possible to automatically generate a YAML schema file or models from
Possible Duplicate: Objective-C: With ARC, what's better? alloc or autorelease initializers? Does ARC automatically
is it possible to automatically export mysql database in phpmyadmin

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.