constants

Defining my own None-like Python constant

佐手、 提交于 2019-12-17 14:54:00
问题 I have a situation in which I'm asked to read collections of database update instructions from a variety of sources. All sources will contain a primary key value so that the code that applies the updates to the database can find the correct record. The files will vary, however, in what additional columns are reported. When I read and create my update instructions I must differentiate between an update in which a column (for instance, MiddleName) was provided but was empty (meaning no middle

How are arrays implemented in java?

心不动则不痛 提交于 2019-12-17 10:54:08
问题 Arrays are implemented as objects in java right? If so, where could I look at the source code for the array class. I am wondering if the length variable in arrays is defined as a constant and if so why it isn't in all capital letters LENGTH to make the code more understandable. 回答1: Although arrays are Objects in the sense that they inherit java.lang.Object, the classes are created dynamically as a special feature of the language. They are not defined in source code. Consider this array:

Using consts in static classes

橙三吉。 提交于 2019-12-17 10:52:45
问题 I was plugging away on an open source project this past weekend when I ran into a bit of code that confused me to look up the usage in the C# specification. The code in questions is as follows: internal static class SomeStaticClass { private const int CommonlyUsedValue = 42; internal static string UseCommonlyUsedValue(...) { // some code value = CommonlyUsedValue + ...; return value.ToString(); } } I was caught off guard because this appears to be a non static field being used by a static

How to select multiple rows filled with constants?

冷暖自知 提交于 2019-12-17 10:12:38
问题 Selecting constants without referring to a table is perfectly legal in an SQL statement: SELECT 1, 2, 3 The result set that the latter returns is a single row containing the values. I was wondering if there is a way to select multiple rows at once using a constant expression, something kind of: SELECT ((1, 2, 3), (4, 5, 6), (7, 8, 9)) I would want something like the above that works and returns a result set with 3 rows and 3 columns. 回答1: SELECT 1, 2, 3 UNION ALL SELECT 4, 5, 6 UNION ALL

Is Java guaranteed to inline string constants if they can be determined at compile time

你离开我真会死。 提交于 2019-12-17 09:34:18
问题 Consider this case: public Class1 { public static final String ONE = "ABC"; public static final String TWO = "DEF"; } public Class2 { public void someMethod() { System.out.println(Class1.ONE + Class1.TWO); } } Typically you would expect the compiler to inline the ONE and TWO constants. However, is this behavior guaranteed? Can you deploy at runtime Class2 without Class1 in the classpath, and expect it to work regardless of compilers, or is this an optional compiler optimization? EDIT: Why on

What is a constant reference? (not a reference to a constant)

半腔热情 提交于 2019-12-17 08:09:22
问题 A pretty theoretical question...Why constant references do not behave the same way as constant pointers and I can actually change the object they are pointing to? They really seem like another plain variable declaration. Why would I ever use them? This is a short example that I run which compiles and runs with no errors: int main (){ int i=0; int y=1; int&const icr=i; icr=y; // Can change the object it is pointing to so it's not like a const pointer... icr=99; // Can assign another value but

How do I declare an array as a constant in Objective-c?

心已入冬 提交于 2019-12-17 06:34:47
问题 The following code is giving me errors: // constants.h extern NSArray const *testArray; // constants.m NSArray const *testArray = [NSArray arrayWithObjects: @"foo", @"bar", nil]; The error I get is initializer element is not constant Or if I take away the pointer indicator (*) I get: statically allocated instance of Objective-C class 'NSArray' 回答1: In short, you can't. Objective-C objects are, with the exception of NSString constants, only ever created at runtime and, thus, you can't use an

How do I declare an array as a constant in Objective-c?

非 Y 不嫁゛ 提交于 2019-12-17 06:34:01
问题 The following code is giving me errors: // constants.h extern NSArray const *testArray; // constants.m NSArray const *testArray = [NSArray arrayWithObjects: @"foo", @"bar", nil]; The error I get is initializer element is not constant Or if I take away the pointer indicator (*) I get: statically allocated instance of Objective-C class 'NSArray' 回答1: In short, you can't. Objective-C objects are, with the exception of NSString constants, only ever created at runtime and, thus, you can't use an

Accessing a class constant using a simple variable which contains the name of the constant

心已入冬 提交于 2019-12-17 04:56:07
问题 I'm trying to access a class constant in one of my classes: const MY_CONST = "value"; If I have a variable which holds the name of this constant like this: $myVar = "MY_CONST"; Can I access the value of MY_CONST somehow? self::$myVar does not work obviously because it is for static properties. Variable variables does not work either. 回答1: There are two ways to do this: using the constant function or using reflection. Constant Function The constant function works with constants declared

C/C++: Optimization of pointers to string constants

☆樱花仙子☆ 提交于 2019-12-17 04:34:27
问题 Have a look at this code: #include <iostream> using namespace std; int main() { const char* str0 = "Watchmen"; const char* str1 = "Watchmen"; char* str2 = "Watchmen"; char* str3 = "Watchmen"; cerr << static_cast<void*>( const_cast<char*>( str0 ) ) << endl; cerr << static_cast<void*>( const_cast<char*>( str1 ) ) << endl; cerr << static_cast<void*>( str2 ) << endl; cerr << static_cast<void*>( str3 ) << endl; return 0; } Which produces an output like this: 0x443000 0x443000 0x443000 0x443000