小编Bra*_*man的帖子

使用具有4个表达式的三元运算符

这是一种可接受的编码实践吗?

public class MessageFormat {
    private static final Color DEFAULT_COLOR = Color.RED;

    private Color messageColor = DEFAULT_COLOR;

    public MessageFormat(Person person) {
        Color color = person.getPreferredColor();
        messageColor = (color != null) ? color : messageColor; // this line
    }
}
Run Code Online (Sandbox Code Playgroud)

或者我最好还是选择经典......

if (color != null) {
    messageColor = color;
}
Run Code Online (Sandbox Code Playgroud)

java variables null ternary-operator

11
推荐指数
1
解决办法
7万
查看次数

匹配单词开头的任何子字符串

例如,用一条线一样previous,我希望模式匹配的线条p,pr,pre,prev,等等,所有的方式达到previous.我不希望它匹配像prevalent或的行previse.除了明显的(^(p|pr|pre|prev|...|previous)$)之外,是否有一种模式可以实现这一目标?

注意:我不需要像上面的模式那样捕获它,而且我使用Perl的正则表达式风格(在Perl中).

regex perl

3
推荐指数
1
解决办法
378
查看次数

实现链表时指针奇怪的问题

我正在尝试在C中实现一个链表,我想将头节点存储在一个单独的结构中.但是,每当我添加另一个节点时,似乎都会以某种方式重新分配头节点.

#include <stdio.h>
#include <stdlib.h>

struct BC_node {
    struct BC_node *next;
    void *data;
};
struct BC_list {
    struct BC_node *head;
    struct BC_node *tail;
};

void
BC_list_push(struct BC_list *list, void *data)
{
    struct BC_node *node = calloc(1, sizeof(struct BC_node));

    if (list->head != NULL)
        printf("head: %d\n", *((int *) (list->head)->data));

    node->next = NULL;
    node->data = data;
    if (list->head == NULL) {
        printf("head is null.\n");
        list->head = node;
    }
    if (list->tail != NULL) {
        (list->tail)->next = node;
    }
    list->tail = node;

    printf("head: %d\n", *((int …
Run Code Online (Sandbox Code Playgroud)

c struct pointers linked-list

0
推荐指数
1
解决办法
230
查看次数

标签 统计

c ×1

java ×1

linked-list ×1

null ×1

perl ×1

pointers ×1

regex ×1

struct ×1

ternary-operator ×1

variables ×1