Questions tagged [class-constants]

In object-oriented programming, a class constant is a constant defined within a class.

In object-oriented programming, a class constant is a defined within a .

97 questions
2
votes
3 answers

C# constructor and constants mystery

why would a static constructor throw exception when it references to a const string in another class. class MyClass { static MyClass() { ExamineLog(); } static ExamineLog() { FilePath…
2
votes
4 answers

PHP object instance of class [DateTime('@-1')] as constant in another class

I am defining a class which has a DateTime object as one of the properties. I want to set its default value to unix timestamp of '-1'. I also want this default value to be constant so that all objects know its value. But I do not want to declare…
wadkar
  • 960
  • 2
  • 15
  • 29
2
votes
3 answers

'this' keyword used in class and objects is a constant pointer?

This question came in my mind due to the following error in my c++ program #include using namespace std; class Test { private: int x; public: Test(int x = 0) { this->x = x; } void change(Test *t) { this = t; } void print() { cout…
2
votes
1 answer

XML put constant settings in App.config file

I have a class called Constants.cs that contains app settings. I want to add an App.config file and put the settings from Constants.cs to App.config file in order to be able to run my application in different environments with same settings. If my…
user14495764
2
votes
1 answer

What's the ideal way to create a constant library for Excel VBA?

I am looking to create a collection of functions for structural calculations. The idea is to have a module or similar I can import into an Excel workbook, and start using the functions in VBA for what I might need. Something I'd need to do initially…
Stgauss
  • 57
  • 1
  • 5
2
votes
1 answer

Crazy UTF-8 entry in a kotlin class' constant pool

When examining the content of a .class file from a Kotlin source (just "Hello World", nothing else) I found an UTF-8 string within the constant pool that is (a) not used anywhere and (b) with strange content. Can any tell me what this is?
Christian
  • 576
  • 1
  • 4
  • 16
2
votes
3 answers

How to assign a variable from another file to a class constant?

I have a set of API keys that are constant across my codebase - I have a dev key and a live key. They are stored in their own 'keys.php' file. I have a class that handles accessing the API and I am storing the keys in the class as class constants. I…
Abraham Brookes
  • 1,720
  • 1
  • 17
  • 32
2
votes
4 answers

Access Class Constants Dynamically in PHP

I want to be able to look up the value of a constant dynamically, but using a variable doesn't work with the syntax.
jcropp
  • 1,236
  • 2
  • 10
  • 29
2
votes
1 answer

Accessing nested static const

I'm trying to use a nested constant within WPF, but XAML doesn't seem to handle nested static classes. namespace MyCommon.Constants { public static class Constants { public static class Formatting { public static…
wonea
  • 4,783
  • 17
  • 86
  • 139
2
votes
7 answers

Overzealous String Constants

I am sure this has been asked before, but in this example I am curious as to what usefulness others can see in separating constants to this degree: public class CoreStringConstants { // Common strings public const string SPACE = " "; public…
dwerner
  • 6,462
  • 4
  • 30
  • 44
2
votes
2 answers

Java constant pool removal at runtime

I have the following Java class: public class Test { public static void main(String[] args) { if (false) { log("String_to_be_never_printed_1"); } if (isPrintable()) { …
benjamin.d
  • 2,801
  • 3
  • 23
  • 35
2
votes
3 answers

Get class constant names in php?

I have a php class with some class constants that indicate the status of an instance. When I'm using the class, after I run some methods on it, I do some checks to make sure that the status is what I expect it to be. For instance, after calling…
user151841
  • 17,377
  • 29
  • 109
  • 171
2
votes
4 answers

Java, interface or composition for constants class

I have a question regarding the design of my program. I have a class A that stores public constant so that i can use these constants in another class. public static final String error_code1 = "Fatal Error"; public static final String error_code2 =…
hades
  • 4,294
  • 9
  • 46
  • 71
2
votes
3 answers

Right way to check if a constant is already defined in a Ruby Class

I have certain classes that are implemented as decorators in my Rails app which is on Ruby 1.8.7 . I keep getting the warning - warning: already initialized constant ABC . Here ABC is the name of the constant. To solve this, I'm using the…
boddhisattva
  • 6,908
  • 11
  • 48
  • 72
2
votes
2 answers

Is there a way to specify ruby class/module constant as value in Ruby YAML file

I have a YAML config file where I want to include specific ruby class/module constants instead of the actual value. For example, instead of putting "loglevel: 0" in the config file, I want "loglevel: Logger::DEBUG". Is there a way to have YAML…
lauracw100
  • 93
  • 1
  • 6