如果我们提供足够的泛型信息,像 Jackson 这样的库可以从 JSON 创建对象。
在杰克逊,我们可以做到
Class<?>[] parameterTypes;
JavaType type = objectMapper.getTypeFactory().constructParametricType(ObjectClass, parameterTypes);
objectMapper.readValue(json, type);
Run Code Online (Sandbox Code Playgroud)
在 java 中,可以通过多种方式定义泛型类,例如一个泛型类具有另一个泛型类,并且可以具有另一个泛型类,为了简单说明,考虑这三个类。
public class MultiLevelGenericTestData<T, V> {
private GenericTestData<T> tGenericTestData;
private GenericTestData<V> vGenericTestData;
}
public class MultiGenericTestData<K, V> {
private K key;
private V value;
}
public class MultiGenericTestDataSameType<T> {
private GenericTestData<T> genericTestData;
private MultiGenericTestData<T, T> multiGenericTestData;
}
Run Code Online (Sandbox Code Playgroud)
我知道类型擦除和其他事情,但有没有办法识别类型 T, V从 的对象中MultiLevelGenericTestData?
我想到的一种方法是检查泛型类型并查看它们的名称并检查所有字段,直到找到所有类型。一旦我们遇到具有相同泛型类型的多个字段的情况,这很快就会变得棘手,例如在MultiGenericTestDataSameType,我们应该只得到一种泛型类型。
// This method should find all type's class names in the list
// that can be …Run Code Online (Sandbox Code Playgroud) 我在这里看ANSI C语法.
此页面包含许多用于ANSI C的Lex/Flex中的正则表达式.
在理解字符串文字的正则表达式时遇到问题.
他们提到正则表达为 \"(\\.|[^\\"])*\"
据我所知,\"这用于双引号,\\用于转义字符,.用于任何字符,除了escape character和*为零或多次.
[^\\"]暗示字符除外\,".
因此,在我看来,正则表达应该是\"(\\.)*\".
你能给出一些正则表达式失败的字符串吗?
要么
他们为什么用过[^\\"]?
Django-channels websocket在AWS服务器上运行良好,直到我安装了letsencript ssl.我尝试了另一个证书,但是wss无效.我看到这个在线部署显示渠道可以在https后面工作:
https://django-channels-example.herokuapp.com/
我跟着andrewgodwin sugestions在这里:
https://github.com/django/channels/issues/248
我把daphne指向了端口8000:
daphne -b 0.0.0.0 vp.asgi:channel_layer --port 8000 -v 2
Run Code Online (Sandbox Code Playgroud)
我在我的javascript中使用了相同的端口:
chatsock = new WebSocket( ws_scheme + '://' + window.location.host + ":8000/chat" );
Run Code Online (Sandbox Code Playgroud)
我的nginx配置:
server {
listen 80;
server_name mysite.com www.example.com;
return 301 https://www.example.com$request_uri;
}
server{
listen 443 ssl;
server_name mysite.com www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
root /home/ubuntu/vp;
access_log /var/log/nginx/guni-access.log;
error_log /var/log/nginx/guni-error.log info;
location /wss/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://0.0.0.0:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection …Run Code Online (Sandbox Code Playgroud) 我有一个Makefile如下
all:
bison -d -v parser.y
flex -o parser.lex.c parser.lex
gcc -o cparser parser.lex.c parser.tab.c -lfl -lm
clean:
rm parser.tab.h parser.tab.c parser.output parser.lex.c
Run Code Online (Sandbox Code Playgroud)
当我在终端中运行make时它只运行目标all.
我已尝试添加
.PHONY:all clean,.PHONY:clean即使它只运行all.我应该在Makefile中进行哪些更改,以便它运行所有目标?
系统配置:
Ubuntu 14.10
GNU Make 4.0