在kotlin中,如何使主构造函数中的属性setter成为私有?
class City(val id: String, var name: String, var description: String = "") {
fun update(name: String, description: String? = "") {
this.name = name
this.description = description ?: this.description
}
}
Run Code Online (Sandbox Code Playgroud)
我希望属性的setter name是私有的,并且公开的getter,我该怎么办?
这段代码不起作用; 它登录到使用https协议的网站.如何解决这个问题呢?代码GetRequestStream()随时随地停止,表示协议违规异常未处理.
string username = "user";
string password = "pass";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://moje.azet.sk/prihlasenie.phtml?KDE=www.azet.sk%2Findex.phtml%3F");
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)";
Console.WriteLine(request.GetRequestStream());
using (StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII))
{
writer.Write("nick=" + username + "&password=" + password);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//Retrieve your cookie that id's your session
//response.Cookies
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
Console.WriteLine(reader.ReadToEnd());
}
Run Code Online (Sandbox Code Playgroud) 我是一个有点新手的程序员(我的意思是我精通许多编程语言,但从未参加过正式的课程)并且想为我自己的目的大量修改Chromium web浏览器.我需要显着更改UI,并对V8嵌入式JavaScript引擎进行一些重大更改,我想知道我可以从哪里开始.我想我真正需要知道的是:
非常感谢任何帮助,以及来自您自己的个人经历的任何智慧宝石.
PS:我正在运行Ubuntu 11.10,如果这有所不同的话.
我想知道如何检查JIT编译器是否已关闭.我有以下代码,这意味着关闭JIT编译器.问题是,我不确定它是否真的这样做.所以我想知道是否有办法检查JIT是否关闭.我查看了Compiler类,但没有任何方法isDisabled/enabled().
码:
Compiler.disable();
Run Code Online (Sandbox Code Playgroud)
任何帮助或方向将受到高度赞赏.
我有一个UserControl,我们将其称为myUC,这是myWindow我的WPF应用程序的主窗口()中的几个UserControl之一. myUC包含许多标准控件,其中一个是按钮,我们称之为myButton.
当我点击时myButton,我想执行myMethod(),它存在于myWindow的代码隐藏中.
问题是,即使存在myUC也不知道myWindow,更不用说myMethod存在了.
我该如何发送消息:'嘿,myWindow,醒来.myUc上的myButton刚刚被点击; 请运行myMethod'?
我正在试驾Visual Studio 11测试版,看起来我遇到了一个重大障碍.
有没有人尝试打开包含带用户控件的WPF窗口的实际生产WPF项目?当我尝试打开包含用户控件的WPF窗口或控件时,设计视图会显示一条很好的错误消息:
"设计视图不适用于x64和ARM目标平台,因为该文档包含自定义元素."
它似乎是一个主要的重要因素...因为这些天大多数开发人员的机器都是x64.
*更新:*
在新的VS 2011 WPF项目中重现了这一点:
立即弹出"设计视图不适用于x64和ARM目标平台......".
一旦删除资源引用,设计器就会再次开始工作.
我尝试从android模拟器发送请求到一个安静的服务器.但我总是得到错误:
415不支持的媒体类型.
客户代码:
public JSONtest() throws Exception, IOException{
HttpPost request = new HttpPost(AppServerIP);
JSONObject param = new JSONObject();
param.put("name", "weiping");
param.put("password", "123456");
StringEntity se = new StringEntity(param.toString());
request.setEntity(se);
HttpResponse httpResponse = new DefaultHttpClient().execute(request);
String retSrc = EntityUtils.toString(httpResponse.getEntity());
System.out.println(httpResponse.getStatusLine().getReasonPhrase());
}
Run Code Online (Sandbox Code Playgroud)
服务器的代码:
public class resource {
@POST
@Path("/trigger")
@Consumes(MediaType.APPLICATION_JSON)
public Response trigger(JSONObject notify) throws Exception{
return Response.status(Response.Status.OK).entity("134124").tag("213q").type(MediaType.APPLICATION_JSON).build();
}
Run Code Online (Sandbox Code Playgroud) 可能重复:
使用IoC进行单元测试
我认为我确实有一个问题,理解单元测试和/或依赖注入的工作方式.我正在使用NUnit和Rhino Mocks进行单元测试,将Ninject用作依赖性感知框架.一般来说,虽然这两个人都适合完美 - 但不知何故,似乎它变得更加复杂和难以理解.
(我会尝试做一个很好的例子,让它保持干净和轻松.这是关于我,骑自行车).
1.)没有DI /单元测试:
如果不知道DI和单元测试,我的代码看起来就像那样 - 我会很高兴:
public class Person
{
public void Travel()
{
Bike bike = new Bike();
bike.Ride();
}
}
public class Bike
{
public void Ride()
{
Console.WriteLine("Riding a Bike");
}
}
Run Code Online (Sandbox Code Playgroud)
骑我的自行车我只需要: new Person().Travel();
2.)使用DI:
我不希望紧耦合,所以我需要一个接口和一个NinjectModule!我有一些开销,但只要代码易于阅读和理解,那就没问题了.我只是传递修改后的Person类的代码,Bike类没有改变:
public class Person
{
IKernel kernel = new StandardKernel(new TransportationModule());
public void Travel()
{
ITransportation transportation = kernel.Get<ITransportation>();
transportation.Ride();
}
}
Run Code Online (Sandbox Code Playgroud)
我仍然可以骑自行车: new Person().Travel();
3.)考虑单元测试(没有DI):
为了能够检查是否正确调用了Ride-Method,我需要一个模拟.据我所知,有两种注入接口的方法:构造函数注入和Setter注入.我为我的例子选择了Constructor Injection:
public class Person …Run Code Online (Sandbox Code Playgroud) 我想在WebView加载页面时为警报对话框设置不同的标题,但它不起作用.
这是代码片段:
final AlertDialog.Builder alert = new AlertDialog.Builder(
mContext);
// alert.setTitle("Loading...");
final WebView wv = new WebView(mContext);
wv.loadUrl("http://10.0.51.133/androidview/");
wv.getSettings().setJavaScriptEnabled(true);
wv.setVerticalScrollBarEnabled(false);
WebViewClientLoader loader= new WebViewClientLoader(alert);
wv.setWebViewClient(loader);
wv.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
alert.setTitle("Loading...");
super.onPageFinished(view, url);
}
@Override
public void onPageStarted(WebView view, String url,
Bitmap favicon) {
// TODO Auto-generated method stub
alert.setTitle("Finished");
super.onPageStarted(view, url, favicon);
}
});
private class webviewclient extends WebViewClient{
}
wv.loadUrl("file:///android_asset/Like.html");
alert.setView(wv);
alert.show();
Run Code Online (Sandbox Code Playgroud)