null

Java null check

末鹿安然 提交于 2019-12-12 12:09:19
问题 I have one thread1 : if(object != null){ object.play(); } and another thread2 that can write null into object reference at any time. I will run these threads at same time. I know thread2 can rewrite object reference after the null check and that will throw NullPointerException . Is it possible for thread2 to rewrite object reference after NullPointerException check? 回答1: Is it possible to for thread2 to rewrite object reference after NullPointerException check ? Absolutely - it could change

Leetcode 430:扁平化多级双向链表

[亡魂溺海] 提交于 2019-12-12 11:42:19
题目描述 您将获得一个双向链表,除了下一个和前一个指针之外,它还有一个子指针,可能指向单独的双向链表。这些子列表可能有一个或多个自己的子项,依此类推,生成多级数据结构,如下面的示例所示。 扁平化列表,使所有结点出现在单级双链表中。您将获得列表第一级的头部。 示例: 输入: 1---2---3---4---5---6--NULL | 7---8---9---10--NULL | 11--12--NULL 输出: 1-2-3-7-8-11-12-9-10-4-5-6-NULL 以上示例的说明: 给出以下多级双向链表: 我们应该返回如下所示的扁平双向链表: 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/flatten-a-multilevel-doubly-linked-list 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 解题思路 class Solution { public: Node* flatten(Node* head) { Node *cur = head; while(cur != NULL){ if(cur->child != NULL){ Node* post = cur->next; Node* child = cur->child; cur->child = NULL; cur-

When can a generic parameter never be null

心已入冬 提交于 2019-12-12 11:21:49
问题 In a generic GetHashCode(T foo) method, I check whether foo is null . However I just stumbled upon a strange Resharper warning. In the following code, can foo never be null ? private class FooComparer<T> : IEqualityComparer<T> where T: Foo { public int GetHashCode(T foo) { // resharper warning: "Expression is always false" if (Object.ReferenceEquals(null,foo)) return 0; // ... calculate hash } } However as far as I can tell, the following is perfectly legal: Foo foo = null; var fooComparer =

How to set Sql DateTime to null from LINQ

本秂侑毒 提交于 2019-12-12 11:05:50
问题 I have two cases when I would need to set DateTime field in Sql to null. I use C# and LINQ to SQL Classes. I read many questions on stackoverflow which are like my question but still I feed mine a bit different. When we insert a new customer. Corresponding code: Customer customer = new Customer(); customer.CustomerName = txt_name.Text; customer.DOB = dtp_dob.Checked ? DateTime.Parse(dtp_dob.Value.ToString("yyyy-MM-dd")) : //send null here; customer.DOB is System.DateTime. What I tried is: 1)

Anyone have issues going from ColdFusion's serializeJSON method to PHP's json_decode?

吃可爱长大的小学妹 提交于 2019-12-12 10:56:38
问题 The Interwebs are no help on this one. We're encoding data in ColdFusion using serializeJSON and trying to decode it in PHP using json_decode . Most of the time, this is working fine, but in some cases, json_decode returns NULL . We've looked for the obvious culprits, but serializeJSON seems to be formatting things as expected. What else could be the problem? UPDATE: A couple of people (wisely) asked me to post the output that is causing the problem. I would, except we just discovered that

.Net C# String.Join how to output “null” instead of empty string if element value is null?

浪尽此生 提交于 2019-12-12 10:49:04
问题 According to the MSDN docs for String.Join "If any element in value is null, an empty string is used instead." The code I have pulls data out of a DataTable rotationValues = string.Join<object>(", ", from r in rotationData.Rows.OfType<DataRow>() select r[5]); This would result in output similar to this: 8, 7, , 12, , , 13, Is there any way to simply have it put "null" in place of an empty string like so: 8, 7, null, 12, null, null, 13, null 回答1: You can select r[5] ?? "null" instead of just r

What is the purpose of the NullObject class in Groovy?

故事扮演 提交于 2019-12-12 10:48:09
问题 I've been using Groovy for all of five hours and just came across the Groovy NullObject. I read the Groovy explanation of the Null Object Pattern, but it doesn't touch on the NullObject class directly; is NullObject merely intended to be a base class for things like NullTree and NullJob ? I'm getting a NullObject back in some code that expects a String , and it's causing a failure much like a "regular" null would have. So, what is the purpose of NullObject ? Or, phrased differently, what

Javascript regex split reject null

大憨熊 提交于 2019-12-12 10:46:27
问题 Is it possible to make a JavaScript regex reject null matches? Can the String.split() method be told to reject null values? console.log("abcccab".split("c")); //result: ["ab", "", "", "ab"] //desired result: ["ab", "ab"] - While I was testing this I came across a partial answer on accident: console.log("abccacaab".split(/c+/)); //returns: ["ab", "a", "aab"] But, a problem arises when the match is at the start: console.log("abccacaab".split(/a+/)); //returns: ["", "bcc", "c", "b"] // ^^ Is

Does dereference a NULL pointer guarantee to crash a program in C/C++?

房东的猫 提交于 2019-12-12 10:44:18
问题 I come across this wired code and it's not crashing. #include <stdio.h> struct s { char* c; char* c2; }; int main() { struct s* p = NULL; printf("%d\n", &(p->c)); printf("%d\n", &p->c2); printf("%d\n", &(*p).c2); return 0; } Output: 0 4 4 I have several question comes to me I cannot answer: Does NULL pointer always equal to 0 in c/c++? What happen if 0 happen to be an address of a variable? It seems the outputs are offset addresses of members of the struct. How does this get calculated. I

Reference pointing to a Null-object

空扰寡人 提交于 2019-12-12 10:41:03
问题 I saw this discussion - Checking for a null object in C++ and I was surprised that no one talked about when reference can point to a null object. In our code, we use null objects routinely. There are functions as follows which return nullObj. const Obj& nullObj() { static obj* nullPtr = NULL; return static_cast< const Obj&>(*nullPtr); } Actually, when I looked at the code again to bring this topic up, I had some questions on how the above code works: How is it possible to do *nullPtr - Is is