到现在为止,我认为数组与指针相同.但我发现了一个奇怪的案例:
int array[5] = { 10,11,12,13,14};
std::cout << array << std::endl;
std::cout << &array << std::endl;
std::cout << &array[0] << std::endl;
int *pArray = new int[5];
std::cout << pArray << std::endl;
std::cout << &pArray << std::endl;
std::cout << &pArray[0] << std::endl;
Run Code Online (Sandbox Code Playgroud)
0x7ffeed730ad0
0x7ffeed730ad0
0x7ffeed730ad0
0x7f906d400340
0x7ffeed730a30
0x7f906d400340
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,array并且&array具有相同的价值.但是pArray并且&pArray有不同的价值.如果数组与指针相同,则数组的地址应与数组不同.怎么可能array和&array是一样的?如果array和&array相同,保存数组值的内存的地址是什么?
代码如下
Set<Thread> threads = new HashSet<>();
Runnable r = () -> {
try {
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
e.printStackTrace();
}
};
for (int i = 0; i < 20000; i++) {
Thread t = new Thread(r);
threads.add(t);
t.start();
if (i % 100 == 0) {
System.out.println(i);
}
Thread.sleep(2);
}
Run Code Online (Sandbox Code Playgroud)
执行时,我开始看到像这样的值
0
100
200
300
Run Code Online (Sandbox Code Playgroud)
正如所料,直到我看到:
3900
4000
Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:717)
at App.main(scratch.java:24)
Java HotSpot(TM) 64-Bit …Run Code Online (Sandbox Code Playgroud) 我已经尝试使用以下代码来使必填字段通知所需的字段但它在Safari浏览器中不起作用.码:
<form action="" method="POST">
<input required />Your name:
<br />
<input type="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
在firefox上面的代码工作.http://jsfiddle.net/X8UXQ/179/
你能让我知道javascript代码或任何workarround吗?我是javascript的新手
谢谢
使用spring,使用以下代码:
List<HttpMessageConverter<?>> messageConverters = restTemplate.getMessageConverters();
for(HttpMessageConverter httpMessageConverter : messageConverters){
System.out.println(httpMessageConverter);
}
ResponseEntity<ProductList> productList = restTemplate.getForEntity(productDataUrl,ProductList.class);
Run Code Online (Sandbox Code Playgroud)
我明白了
org.springframework.http.converter.ByteArrayHttpMessageConverter@34649ee4
org.springframework.http.converter.StringHttpMessageConverter@39fba59b
org.springframework.http.converter.ResourceHttpMessageConverter@383580da
org.springframework.http.converter.xml.SourceHttpMessageConverter@409e850a
org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter@673074aa
org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter@1e3b79d3
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@52bb1b26
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.mycopmany.ProductList] and content type [text/html;charset=UTF-8]
Run Code Online (Sandbox Code Playgroud)
pojo的片段:
@XmlRootElement(name="TheProductList")
public class ProductList {
@XmlElement(required = true, name = "date")
private LocalDate importDate;
Run Code Online (Sandbox Code Playgroud) 有什么区别
import javax.annotation.ManagedBean;
import javax.enterprise.context.SessionScoped;
Run Code Online (Sandbox Code Playgroud)
和
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
Run Code Online (Sandbox Code Playgroud)
?
这是来自Oracle的JDK 8实现的Stream接口:
public interface Stream<T> extends BaseStream<T, Stream<T>> {
Stream<T> sorted();
}
Run Code Online (Sandbox Code Playgroud)
并且很容易在运行时将其清除,并且在编译时不会生成警告.这是一个例子:
class Foo {
public static void main(String[] args) {
Arrays.asList(new Foo(), new Foo()).stream().sorted().forEach(f -> {});
}
}
Run Code Online (Sandbox Code Playgroud)
这将编译得很好,但会在运行时抛出异常:
Exception in thread "main" java.lang.ClassCastException: Foo cannot be cast to java.lang.Comparable
Run Code Online (Sandbox Code Playgroud)
sorted在编译器实际可以捕获这些问题的地方没有定义该方法的原因是什么?也许我错了,但不是这么简单:
interface Stream<T> {
<C extends Comparable<T>> void sorted(C c);
}
Run Code Online (Sandbox Code Playgroud)
?
显然,那些实现这一点的人(考虑到编程和工程方面比我早了几年)必须有一个很好的理由,我无法看到,但这是什么原因?
我正在研究这本书(我强烈推荐),我很困惑作者如何解释Spring框架的配置方式.
您可以在此处查看本书中使用的一些代码示例.(任何人都可以使用它们.)如果你想看一下,我所指的代码将是第2章的代码.
无论如何,本书指出有三种配置Spring容器的方法.
基于XML的配置
这将需要一个类似于下面的xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" ...>
<bean id="accountService" class="com.wiley.beginningspring.ch2.AccountServiceImpl">
<property name="accountDao" ref="accountDao"/>
</bean>
<bean id="accountDao" class="com.wiley.beginningspring.ch2.AccountDaoInMemoryImpl">
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
然后为了引导Spring,将使用的代码是:
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("/com/wiley/beginningspring/ch2/ch2-beans.xml");
Run Code Online (Sandbox Code Playgroud)
我此刻没有任何困惑.
基于Java的配置
在此Configuration方法中,将有一个配置类,如下所示:
@Configuration
public class Ch2BeanConfiguration {
@Bean
public AccountService accountService() {
AccountServiceImpl bean = new AccountServiceImpl();
bean.setAccountDao(accountDao());
return bean;
}
@Bean
public AccountDao accountDao() {
AccountDaoInMemoryImpl bean = new AccountDaoInMemoryImpl();
return bean;
}
}
Run Code Online (Sandbox Code Playgroud)
并且负责引导Spring的代码如下所示:
ApplicationContext applicationContext
= new AnnotationConfigApplicationContext(Ch2BeanConfiguration.class);
Run Code Online (Sandbox Code Playgroud)
所以到了这里,对我来说一切都很清楚.(有点......)我还要注意,这里我们实际上有一个名为@Configuration的Annotation ...
基于注释的配置 …
这是来自HeadFirst Java :(第575页)
这个:
public <T extends Animal> void takeThing(ArrayList<T> list)
Run Code Online (Sandbox Code Playgroud)
与此相同:
public void takeThing(ArrayList<? extends Animal> list)
Run Code Online (Sandbox Code Playgroud)
所以这是我的问题:如果它们完全相同,我们为什么不写
public <? extends Animal> void takeThing(ArrayList<?> list)
Run Code Online (Sandbox Code Playgroud)
要么
public void takeThing(ArrayList<T extends Animal> list)
Run Code Online (Sandbox Code Playgroud)
此外,何时使用?有用?使用泛型或类声明的方法声明(如上所述)中的T而不是T?有什么好处?
在python中使用Pandas包,我想在一个系列中使用3级多索引对一个级别进行求和(边缘化)以生成具有2级多索引的系列.例如,如果我有以下内容:
ind = [tuple(x) for x in ['ABC', 'ABc', 'AbC', 'Abc', 'aBC', 'aBc', 'abC', 'abc']]
mi = pd.MultiIndex.from_tuples(ind)
data = pd.Series([264, 13, 29, 8, 152, 7, 15, 1], index=mi)
A B C 264
c 13
b C 29
c 8
a B C 152
c 7
b C 15
c 1
Run Code Online (Sandbox Code Playgroud)
我想总结变量C以产生以下输出:
A B 277
b 37
a B 159
b 16
Run Code Online (Sandbox Code Playgroud)
熊猫做这件事的最佳方式是什么?
java ×5
c++ ×2
spring ×2
xml ×2
arrays ×1
cdi ×1
comparable ×1
generics ×1
html ×1
html5 ×1
java-8 ×1
java-stream ×1
jaxb ×1
jsf ×1
macos ×1
managed-bean ×1
multi-index ×1
pandas ×1
pointers ×1
python ×1
safari ×1
statistics ×1
wildcard ×1