我遇到像这样的Java代码:
public interface Foo<E> {}
public interface Bar<T> {}
public interface Zar<?> {}
Run Code Online (Sandbox Code Playgroud)
上述所有这三者之间有什么区别,他们在Java中称这种类或接口声明是什么?
当我在谷歌浏览器中打开开发人员工具时,我会看到各种功能,如个人资料,时间轴和审核,但基本功能,如能够在js文件和html和javascript代码中设置断点!我试图使用javascript控制台,它本身就是错误的 - 例如,一旦遇到JS错误,除非我刷新整个页面,否则我无法摆脱它.有人可以帮忙吗?
我有一个返回List的Java API,如:
public List<?> getByXPath(String xpathExpr)
Run Code Online (Sandbox Code Playgroud)
我使用下面的scala代码:
val lst = node.getByXPath(xpath)
Run Code Online (Sandbox Code Playgroud)
现在,如果我尝试scala语法糖,如:
lst.foreach{ node => ... }
Run Code Online (Sandbox Code Playgroud)
这是行不通的.我收到错误:
value foreach is not a member of java.util.List[?0]
Run Code Online (Sandbox Code Playgroud)
看来我需要将Java List转换为Scala List.如何在上述背景下做到这一点?
我有scala地图:
attrs: Map[String , String]
Run Code Online (Sandbox Code Playgroud)
当我尝试迭代地图时;
attrs.foreach { key, value => }
Run Code Online (Sandbox Code Playgroud)
以上不起作用.在每次迭代中,我必须知道什么是关键,什么是价值.使用scala语法糖迭代scala map的正确方法是什么?
在Groovy语言中,检查null
或更false
喜欢它非常简单:
常规代码:
def some = getSomething()
if(some) {
// do something with some as it is not null or emtpy
}
Run Code Online (Sandbox Code Playgroud)
在Groovy中,如果some
是null
或是空字符串或是零数字等将评估为false
.在Scala中null
或false
Scala 中测试的类似简洁方法是什么?这部分问题的简单答案是什么,假设some
只是Java类型的String?
另外一个更好的方法是groovy:
def str = some?.toString()
Run Code Online (Sandbox Code Playgroud)
这意味着如果some
不是null
,则toString
在方法some
将被调用,而不是在壳体投掷NPE some
是null
.Scala有什么相似之处?
我有两个视图占据整个屏幕,我想同时显示两个视图,一个在另一个上面.我的布局看起来像这样:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<org.example.myCustomView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
请注意,myCustomView
使用onDraw(此方法的最后一个语句是invalidate())来绘制自定义图形.我得到的问题是它只显示myCustomView
,WebView
是隐藏的.我试图将背景颜色更改mycustomView
为透明,但这没有任何区别.
我也希望有能力myCustomView
作为叠加,WebView
反之亦然.
我想在scala单例类中定义一个看起来像的私有方法;
private def createDomNode(tag: String, attrs: Map[String , String]): DomNode {
}
Run Code Online (Sandbox Code Playgroud)
DomNode是Java类型,而不是scala类型.attrs是scala Map,其键和值都是String类型.
但上面给出了错误.什么是正确的格式?
谢谢Easy Angel的答案.仍有一些困惑.根据该语言的发明者编写的Scala编程书,下面是一个函数:
def max(x: Int, y: Int): Int = {
if (x > y) x
else y
}
Run Code Online (Sandbox Code Playgroud)
但是你的回答是它是方法而不是功能.你能解释一下吗?
什么是REPL?
我有Spring Boot 2网络应用程序,我需要通过cookie识别网站访问者并收集页面查看统计信息.所以我需要拦截每个Web请求.我必须编写的代码比回调地狱更复杂(Spring反应堆应该解决的问题).
这是代码:
package mypack.conf;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;
import org.springframework.http.HttpCookie;
import org.springframework.http.ResponseCookie;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import mypack.dao.PageViewRepository;
import mypack.dao.UserRepository;
import mypack.domain.PageView;
import mypack.domain.User;
import mypack.security.JwtProvider;
import reactor.core.publisher.Mono;
@Configuration
@ComponentScan(basePackages = "mypack")
@EnableReactiveMongoRepositories(basePackages = "mypack")
public class WebConfig implements WebFluxConfigurer {
@Autowired
@Lazy
private UserRepository userRepository;
@Autowired
@Lazy
private PageViewRepository pageViewRepository;
@Autowired …
Run Code Online (Sandbox Code Playgroud) 我想从iframe默认的普通白色背景和黑色文本中为iframe中的内容制作背景颜色为黑色和文本颜色为白色.iframe src属性指向我无法访问的不同域,或者无法在该域中放置任何文件或样式表.因此,鉴于这些条件,可以在iframe内容中进行这些样式更改,如果是,那么如何?
假设我有以下功能:
function foo() {
}
function bar() {
}
Run Code Online (Sandbox Code Playgroud)
我可以在上面写为Object Literal表示法:
var Baz = {
foo: function() {
},
bar: function() {
}
};
Run Code Online (Sandbox Code Playgroud)
据我所知,在后一种情况下,无论是否调用任何Baz函数,脚本加载时都会创建一个Baz实例.在前一种情况下,仅在调用该函数时才创建函数对象.我对这些假设是否正确?
如果我是正确的那么前者将具有比后者在很少调用这些函数的应用程序中更高的性能(更少的内存).但后者的优势在于它提供了更大的模块化和更低的全局命名空间污染.
您从专业经验中对此有何看法?有速度差吗?