用Java中的方法使用"this"怎么样?它是可选的还是有需要使用它的情况?
我遇到的唯一情况是在类中调用方法中的方法.但它是可选的.这是一个愚蠢的例子,只是为了表明我的意思:
public class Test {
String s;
private String hey() {
return s;
}
public String getS(){
String sm = this.hey();
// here I could just write hey(); without this
return sm;
}
}
Run Code Online (Sandbox Code Playgroud) 几天来我一直坚持这个问题.
所以我有一个以下形式的对象数据集:
dataset = [{metric:"revenue",value:0.03},{metric:"sales", value:0.15},{metric:"churn", value: 0.06},{metric:"logins", value: 0.45}]
Run Code Online (Sandbox Code Playgroud)
以下代码将以网格模式显示4个度量标准名称(meshy,meshx是网格的坐标点,meshsize是网格的大小,因此这只是将文本放在网格方块的中间):
svg.selectAll("text")
.data(dataset)
.enter()
.append("text")
.text(function(d){
return d.metric;
})
.attr("y",function(d,i){
return meshy[i] + meshsize/2;
})
.attr("x", function(d,i){
return meshx[i] + meshsize/2;
})
.attr("font-size",25)
.attr("font-family","serif")
.attr("text-anchor","middle")
.attr("font-weight","bold");
Run Code Online (Sandbox Code Playgroud)
现在我想将度量标准的值放在度量标准名称下面,如下所示:
svg.append("text")
.data(dataset)
.text(function(d){
return (d.value);
})
.attr("y",function(d,i){
return meshy[i] + meshsize/2 + 20;
})
.attr("x", function(d,i){
return meshx[i] + meshsize/2 ;
})
.attr("font-size",25)
.attr("font-family","serif")
.attr("text-anchor","middle")
.attr("font-weight","bold");
Run Code Online (Sandbox Code Playgroud)
但是这只返回FIRST度量标准名称下面的值,其他3个值文本甚至不在DOM中.我尝试了多种方法,包括用.html替换.text,如下所述:https://github.com/mbostock/d3/wiki/Selections#wiki-html但没有成功.我也尝试添加段落元素 - 这是有效的,但是p元素位于列表中的svg体下方,没有明显的方法将它们移动到正确的位置.上面的代码是我最接近我需要的代码,但由于某种原因,只显示第一个值文本.但是,我对d3中完成任务的任何方法持开放态度:4个度量标准名称,其值正好位于其下方
我必须允许用户在我的Android应用程序到PHP服务器的单个请求中上传多个文件(可以是图像/视频/音频).我正在使用REST Web服务.
对于此功能,我使用以下代码:
/* To upload the multiple documents */
public void uploadFile() {
String charset = "UTF-8";
File[] uploadFileArray = new File[mediaList.size()];
for (int i = 0; i < mediaList.size(); i++) {
uploadFileArray[i] = new File(mediaList.get(i).getMediaPath());
}
try {
MultipartUtility multipart = new MultipartUtility(upLoadServerUri, charset);
for (int i = 0; i < mediaList.size(); i++) {
if (isImage)) {
multipart.addFilePart("image_doc[]", uploadFileArray[i]);
}
else if (isVideo) {
multipart.addFilePart("video_doc[]", uploadFileArray[i]);
}
else if (isAudio) {
multipart.addFilePart("audio_doc[]", uploadFileArray[i]);
}
}
List<String> responseUploadDocument = …Run Code Online (Sandbox Code Playgroud) 我是C的新手,试图找出C中的内存分配,我有点困惑
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int a;
} struct1_t;
int main()
{
funct1(); //init pointer
return 1;
}
int funct2(struct1_t *ptr2struct)
{
printf("print a is %d\n",ptr2struct->a);
//free(ptr2struct);
printf("value of ptr in funct2 is %p\n", ptr2struct);
return 1; //success
}
int funct1(){
struct1_t *ptr2struct = NULL;
ptr2struct = malloc(sizeof(*ptr2struct));
ptr2struct->a = 5;
printf("value of ptr before used is %p", ptr2struct);
if (funct2(ptr2struct) == 0) {
goto error;
}
free(ptr2struct);
printf("value of ptr in funct1 after freed is is …Run Code Online (Sandbox Code Playgroud) 我一直试图理解Scanner的工作方式,一直绞尽脑汁.所以这是代码:
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
String p = sc.nextLine();
System.out.println(s);
System.out.println(p);
System.out.println(sc.hasNextLine());
Run Code Online (Sandbox Code Playgroud)
我期待的是:
Love is good <- press ENTER
Love is blind <- press ENTER
Love is good <- output
Love is blind <- output
false
Run Code Online (Sandbox Code Playgroud)
我有什么:
Love is good <- I press ENTER
Love is blind <- I press ENTER
Love is good <- output
Love is blind <- output
<- press ENTER
true <- output
Run Code Online (Sandbox Code Playgroud)
我不明白的是:
在以下代码的最后一行中,它有 &2, if($page['special']&2).
这是什么意思?
if(isset($_REQUEST['id']))$id=(int)$_REQUEST['id'];
else $id=0;
if($id){ // check that page exists
$page=dbRow("SELECT * FROM pages WHERE id=$id");
if($page!==false){
$page_vars=json_decode($page['vars'],true);
$edit=true;
}
}
if(!isset($edit)){
$parent=isset($_REQUEST['parent'])?(int)$_REQUEST['parent']:0;
$special=0;
if(isset($_REQUEST['hidden']))$special+=2;
$page=array('parent'=>$parent,'type'=>'0','body'=>'','name'=>'','title'=>'','ord'=>0,'description'=>'','id'=>0,'keywords'=>'','special'=>$special,'template'=>'');
$page_vars=array();
$id=0;
$edit=false;
}
// { if page is hidden from navigation, show a message saying that
if($page['special']&2)echo '<em>NOTE: this page is currently hidden from the front-end navigation. Use the "Advanced Options" to un-hide it.</em>';
Run Code Online (Sandbox Code Playgroud) 如何在弹性搜索中找出索引创建日期?
这是有道理的.但是对于这个问题,有哪些首选的工作方法呢?
我有一个程序返回一组具有如下排名的域:
ranks = [
{'url': 'example.com', 'rank': '11,279'},
{'url': 'facebook.com', 'rank': '2'},
{'url': 'google.com', 'rank': '1'}
]
Run Code Online (Sandbox Code Playgroud)
我试图通过提升等级对它们进行排序sorted:
results = sorted(ranks,key=itemgetter("rank"))
Run Code Online (Sandbox Code Playgroud)
但是,由于"rank"的值是字符串,因此它按字母数字而不是按升序值对它们进行排序:
1. google.com: 1
2. example.com: 11,279
3. facebook.com: 2
Run Code Online (Sandbox Code Playgroud)
我需要将"rank"键的值转换为整数,以便它们能够正确排序.有任何想法吗?