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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:46:57+00:00 2026-06-07T02:46:57+00:00

I just want have a final List with colors : final List<String> COLORS =

  • 0

I just want have a final List with colors :

final List<String> COLORS =  ['#cefbe4', '#81ec72', '#5cd646'];
final num MAX = 90;
class Square {
 // ...

It’s ok for MAX but it does not compile for list :
Initializer must be a compile time constant

I also tried :

static final num MAX = 90;
class Square {
    final List<String> COLORS =  ['#cefbe4', '#81ec72', '#5cd646'];

New error : “initializer must be a compile time constant”

The only solution, I found is to initialise in constructor…
I don’t like this solution : I don’t want a list instance by Square object.
How can I do ?

  • 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-07T02:46:59+00:00Added an answer on June 7, 2026 at 2:46 am

    I don’t get the same errors as you. In the first case I get a compile time warning “Expected constant expression” and in the second case another compile-time warning and a runtime error. Try the latest SDK which you can find here.

    static final num MAX = 90;
    class Square {
        final List<String> COLORS =  ['#cefbe4', '#81ec72', '#5cd646'];
    

    In this case static it doesn’t make any sense because static denotes class variables which are the same for all instantiated objects of the same class. And in this case MAX is outside a class boundary. Hence a runtime error is shown and a compile time warning (“Top-level field cannot be static”).

    I guess both MAX and COLORS are supposed to be the same for all instances of the Square class. So it makes sense to do this:

    class Square {
        static final List<String> COLORS = const ['#cefbe4', '#81ec72', '#5cd646'];
        static final num MAX = 90;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that inherits QMainWindow and I just want it to have
I just want to have my anchor in the middle of the screen horizontally,
I just want to have other opinions about this one that I have been
I won't want to have edit any working sets. I just want a way
I just want what my title says.I have already read all the previous similar
I just want to know how to access an array in SMARTY that have
I just want to know that can i make an application which have some
Hi I just want to make sure I have these concepts right. Overloading in
I have a FormCollection and I just want to only iterate through the keys
I have a placholder that I dont just want to use Visible=false on, becouse

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.