null

Can't check if int is null

試著忘記壹切 提交于 2019-12-23 06:57:09
问题 I'm trying to use a dictionary. Whenever I want to check if an element is present in the dictionary, I do this: int value = results.get("aKeyThatMayOrMayNotBePresent"); if (value != null) // ... But then the compiler says I can't compare an int to a <nulltype> . What's the correct way to check for null in this case? 回答1: You're comparing a primitive value (int) to null. Since primitives cannot be null, you should use a corresponding object, such as Integer in this case. So, you should write

When to use Q_NULLPTR?

余生长醉 提交于 2019-12-23 06:50:32
问题 I see Q_NULLPTR being used liberally in Qt source code and examples, but I have found no documentation for what it is exactly and when it should be used. For example in this official demonstration of the new Qt SerialBus module added in the new Qt v5.6: if (!m_canDevice->connectDevice()) { delete m_canDevice; m_canDevice = Q_NULLPTR; Did this serve the purpose of nullptr prior to that being added in C++11? If so, now that we have C++11, should I be using Q_NULLPTR ? PS: I tried searching the

Casting null as an object?

懵懂的女人 提交于 2019-12-23 06:48:05
问题 I came across this code today AsyncInvoke(OnTimeMessageTimer, (object)null, (ElapsedEventArgs)null); Is there anything wrong with it or no? 回答1: Sometimes, you need to to this when the method is overloaded... to tell the compiler which one you are calling. A null object is still null and it is safe. 回答2: it probably needs the cast to resolve overloads 来源: https://stackoverflow.com/questions/358079/casting-null-as-an-object

Checking instance of non-class constrained type parameter for null in generic method

三世轮回 提交于 2019-12-23 05:15:31
问题 I currently have a generic method where I want to do some validation on the parameters before working on them. Specifically, if the instance of the type parameter T is a reference type, I want to check to see if it's null and throw an ArgumentNullException if it's null. Something along the lines of: // This can be a method on a generic class, it does not matter. public void DoSomething<T>(T instance) { if (instance == null) throw new ArgumentNullException("instance"); Note, I do not wish to

JSF javax.faces.convert Converter getAsString Object null

泪湿孤枕 提交于 2019-12-23 04:52:30
问题 I am working on an application and I used JSF within this application, I wrote a Java class which implements this interface JSF javax.faces.convert , and also overwrite the method getAsString of Converter, here is the Java doc of this method: java.lang.String getAsString(FacesContext context, UIComponent component, java.lang.Object value) But sometimes, the value here is Null , sometimes it works well, does anybody know that why this value is null here? how to prevent it to happen? 回答1: It

Excel Sum if not Null String

自闭症网瘾萝莉.ら 提交于 2019-12-23 02:33:11
问题 I would like to sum all cells in column B that corresponds to cells in column A which are not empty. However, in Excel, the term "not empty" is a bit ambigious: if a cell contains a formula, but the result is a null string, i.e. =IF(1=0,1,"") , it is considered not empty, even though the result is essentially nothing. However, I want to exclude such cells. The obvious thing to try first is =SUMIF(A:A,"<>",B:B) But this does not work, because the operator <> only says a cell is empty if it is

HttpContext is null in a method called inside Parallel.For

家住魔仙堡 提交于 2019-12-22 17:39:32
问题 Posting this question after trying a lot. Doing normal for is not an option because we need to do a large amount of processing in very less time. I have GetDataFor() inside which HttpContext.Current is used. The code looks like this: public void SomeMethod() { var context = HttpContext.Current; Parallel.For(0, 100, i => { var data = GetDataFor(i, context); }); } public data GetDataFor(int i, HttpContext context) { Uri requestUri = null; if (HttpContext.Current != null) { requestUri =

count(1),count(*),count(字段),explain 分析

久未见 提交于 2019-12-22 17:00:38
预先准备 有主键有索引的表 emp id 是主键, name 是普通索引,可为NULL dep_id 普通字段 DROP TABLE IF EXISTS `emp`; CREATE TABLE `emp` ( `id` int(11) NOT NULL, `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `dep_id` int(11) NULL DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE, INDEX `idx_name`(`name`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of emp -- ---------------------------- INSERT INTO `emp` VALUES (1, 'z3', 1); INSERT INTO `emp` VALUES (2, 'w3', 2); INSERT INTO `emp` VALUES (3, 'w4', 2);

Passing null to `XslCompiledTransform.Transform` method

二次信任 提交于 2019-12-22 13:56:29
问题 I am trying to transform and XML document using XSL. I am not too familiar with how to transform XML in .NET so I am using some example code ... XslCompiledTransform xslTransformer = new XslCompiledTransform(); xslTransformer.Load(Server.MapPath("Test.xslt")); MemoryStream ms = new MemoryStream(); xslTransformer.Transform(Server.MapPath("Test.xml"), null, ms); ms.Seek(0, SeekOrigin.Begin); StreamReader sr = new StreamReader(ms); string output = sr.ReadToEnd(); ms.Close(); Response.Write

How would I go about fixing a NullPointerException of the following code?

被刻印的时光 ゝ 提交于 2019-12-22 12:53:20
问题 I have this code and when I run the script, I pass in valid parameters, but I keep on getting a NPE. Help? Code: private static Date getNearestDate(List<Date> dates, Date currentDate) { long minDiff = -1, currentTime = currentDate.getTime(); Date minDate = null; if (!dates.isEmpty() && currentDate != null) { for (Date date : dates) { long diff = Math.abs(currentTime - date.getTime()); if ((minDiff == -1) || (diff < minDiff)) { minDiff = diff; minDate = date; } } } return minDate; } I get the