default

How to change what default(T) returns in C#?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 14:43:49
I would like to change how default(T) behaves for certain classes. So instead of returning null for my reference types I would like to return a null object. Kind of like kids.Clear(); var kid = kids.Where(k => k.Age < 10).SingleOrDefault(); if (kid is NullKid) { Console.Out.WriteLine("Jippeie"); } Anyone know if this is at all possible? Anyone know if this is at all possible? It is simply not possible at all. But maybe you want to use DefaultIfEmpty instead: kids.Clear(); var kid = kids.Where(k => k.Age < 10).DefaultIfEmpty(NullKid).Single(); if (kid == NullKid) { Console.Out.WriteLine(

Method returning default browser as a String?

一世执手 提交于 2019-11-27 14:41:04
问题 Is there a method that will return a user's default browser as a String? Example of what I am looking for: System.out.println(getDefaultBrowser()); // prints "Chrome" 回答1: You can accomplish this method by using registries [1] and regular expressions to extract the default browser as a string. There isn't a "cleaner" way to do this that I know of. public static String getDefaultBrowser() { try { // Get registry where we find the default browser Process process = Runtime.getRuntime().exec("REG

SQL Server: Find out default value of a column with a query

青春壹個敷衍的年華 提交于 2019-11-27 14:35:05
How can I find out the default value of a column in a table using a SQL query? By using this stored procedure: sp_columns @tablename I get some information on the columns of a particular table but the default value of the columns is missing, How can I get it? You can find the stored definition with the below (remember to adjust the column and table name to find to be ones relevant to your environment!) SELECT object_definition(default_object_id) AS definition FROM sys.columns WHERE name ='colname' AND object_id = object_id('dbo.tablename') OMG Ponies Use: SELECT so.name AS table_name, sc.name

Define Default Activity (when app starts) programmatically

試著忘記壹切 提交于 2019-11-27 14:21:53
问题 My application is composed by a few activity. Activity A is my main menu with some icons. This Activity can launch depending on which icon you press: Activity B,C,D,E or F. That's fine and really easy, Activity A is the default one. Now, I made an option in preference that allow users to start their favourite activity. Some users will in fact prefer to get directly Activity B for instance. The only way I found a solution was to do this in Activity A This solution is very ugly because Activity

How to find default browser set on android device

巧了我就是萌 提交于 2019-11-27 14:03:28
Is there any way to find out which browser is set as a default browser on android device? On android device there may be multiple browsers installed but out of which only one set as a default. I need to find it out programmatically. Thanks in advance. Early response is appreciated.. exloong This code may help you: Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://")); ResolveInfo resolveInfo = getPackageManager().resolveActivity(browserIntent,PackageManager.MATCH_DEFAULT_ONLY); // This is the default browser's packageName String packageName = resolveInfo

Java Map implementation that returns a default value instead of null

爷,独闯天下 提交于 2019-11-27 12:47:13
问题 I have a Map<String, List<String>> in my code, where I'd avoid potential null pointers if the map's #get() method returned an empty list instead of null. Is there anything like this in the java API? Should I just extend HashMap ? 回答1: @Jon's answer is a good way to do what you are asking directly. But is strikes me that what you might be trying to implement is a "multimap"; i.e. a mapping from a key to a collection of values. If that is the case, then you should also look at the multimap

How to change Android O / Oreo / api 26 app language

笑着哭i 提交于 2019-11-27 12:08:07
I want to change the language of the app and this works fine until API 26. For api > 25 I put Locale.setDefault(Locale.Category.DISPLAY, mynewlanglocale); before setContentView(R.layout.activity_main); but nothing changes. The docs don't explain too much about this. Rajalakshmi Arumugam Yes in android Oreo localization is not working fine with updateconfiguration. But it is deprecated in android N itself. Instead of updateconfiguration use createconfiguration in each attachcontext. it is working fine for me. Try this... In you activity add this.. @Override protected void attachBaseContext

How do :default => 0 and :null => false differ for integer fields in migrations?

五迷三道 提交于 2019-11-27 11:53:11
问题 If I use a migration to update a database, and I add an integer field like this: t.integer :foo :default => 0, :null => false What is the default state of existing and new records in the database? I hoping the answer is: - Both will read back foo as 0. Is default => 0 necessary, if I have :null => false? Just trying to understand the difference between the two... 回答1: :null => false tells your database not to accept NULL values. :default => 0 does two things: Tell your database to use '0' as

default copy constructor

﹥>﹥吖頭↗ 提交于 2019-11-27 10:47:43
问题 Can the (implicit) default copy constructor be called for a class that has already user-defined constructor but that is not the copy constructor ? If it is possible then, suppose we define the copy constructor for the class explicitly , now can the (implicit)default constructor be called? 回答1: First, let's clarify our vocabulary a bit. A default constructor is a constructor which can be called without any arguments. A copy constructor is a constructor which can be called with a single

Primitives/Objects Declaration, default initialization values

故事扮演 提交于 2019-11-27 09:35:33
When declaring primitives/objects, are them initialized? Which are the default value? What is the behavior on class members and local fields ? What about objects declaration on class members? As answered below, these are the default values: Data Type - Default Value (for fields) byte 0 short 0 int 0 long 0L float 0.0f double 0.0d char '\u0000' String (or any object) null boolean false Please note that objects are initialized as null The default value of int is 0 and that is the value it will have in both JavaSE and JavaEE unless it was assigned with another value. You can't have an