标签: method-call

Java,一个接一个地调用对象上的方法(C#样式)

我想知道Java是否有这样的形式:

new Object().methodOne("This is the first method").methodTwo("Second attached method");
new String("Hello World  ").TrimEnd().Split(' ');
Run Code Online (Sandbox Code Playgroud)

谢谢

c# java syntax invoke method-call

1
推荐指数
1
解决办法
122
查看次数

没有调用JSF Backing Bean方法

当我单击触发editUser(User)方法的命令按钮或在我的辅助bean中触发editClient(User)方法的方法时,不再调用这些方法.它以前工作过,但现在什么也没有.页面重新加载.

这可能有什么问题?

这是我的观点:

<p:accordionPanel activeIndex="#{userManagement.activeOverviewTab}" id="overview" rendered="#{loginControl.isAllowedForClientUserCreation()}">
<p:tab title="#{text.tabClients}" rendered="#{loginControl.isAllowedForUserManagement()}">
    <h:form id="clientForm">
    <p:dataTable value="#{userManagement.clientUsers}" var="clientUser" paginator="true" rows="5" id="clientTable">
        <p:column><f:facet name="header"><h:outputText value="#{text.colClientName}"/></f:facet><h:outputText value="#{clientUser.client.clientName}"/></p:column>
        <p:column><f:facet name="header"><h:outputText value="#{text.colClientEmail}"/></f:facet><h:outputText value="#{clientUser.client.email}"/></p:column>
        <p:column><f:facet name="header"><h:outputText value="#{text.colClientJobLayout}"/></f:facet><h:outputText value="#{clientUser.client.reportLayout}"/></p:column>
        <p:column><f:facet name="header"><h:outputText value="#{text.colUsersLogin}"/></f:facet><h:outputText value="#{clientUser.login}"/></p:column>
        <p:column><f:facet name="header"><h:outputText value="#{text.colUsersPassword}"/></f:facet><h:outputText value="#{clientUser.password}"/></p:column>            
        <p:column><f:facet name="header"><h:outputText value="#{text.colUsersAction}"/></f:facet>
            <p:commandLink onclick="clientDlg.show()">
                <h:graphicImage name="icons/pencil.png" title="#{text.editClientUser}" />
            </p:commandLink>
                <p:dialog header="#{text.editClientUser}" widgetVar="clientDlg" modal="true" resizable="false" width="350" height="190" showEffect="slide" hideEffect="explode">
                <h:form id="customerEditForm">
                <p:growl id="clientUserMessages"/>
                <br/>
                <p:panelGrid columns="2" columnsClasses="odd, even">
                    <h:outputLabel value="#{text.colClientName}"/><h:inputText value="#{clientUser.client.clientName}" />
                    <h:outputLabel value="#{text.colClientEmail}"/><h:inputText value="#{clientUser.client.email}" />
                    <h:outputLabel value="#{text.colClientJobLayout}"/><h:inputText value="#{clientUser.client.reportLayout}" />
                    <h:outputLabel value="#{text.colUsersLogin}"/><h:inputText …
Run Code Online (Sandbox Code Playgroud)

jsf method-call primefaces backing-beans

1
推荐指数
1
解决办法
6377
查看次数

这是在iOS中调用方法的正确方法

我曾经使用iOS,但我没有得到这个所有方法有什么区别,

我应该使用哪种语法来调用MehodName

 (1) [self MehodName];

 (2) [self performSelector:@selector(MehodName) withObject:nil];

 (3) [self performSelectorInBackground:@selector(MehodName) withObject:nil];

 (4) [self performSelectorOnMainThread:@selector(MehodName) withObject:nil waitUntilDone:YES];

 (5) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 
                                         (unsigned long)NULL), ^(void) {
    [self MehodName];
});

  (6) dispatch_sync(dispatch_get_main_queue(), ^{
     [self MehodName];       
});
Run Code Online (Sandbox Code Playgroud)

请提前帮助和谢谢.

objective-c method-call

1
推荐指数
1
解决办法
167
查看次数

如何验证非模拟方法被调用?

我想测试我的方法在无法模拟的同一类中调用了另一个方法。

例:

public void methodToTest(){

//other stuff to test that can be mocked
someClassICanMock.doSomething();

//method within same class that cannot be mocked
methodFromSameClassIWantToVerify();

}
Run Code Online (Sandbox Code Playgroud)

我如何使用a verify来检查我的测试方法methodFromSameClassIWantToVerify();?

编辑:不是重复的,因为我专门指的是如何使用Mockito对此进行测试。

java unit-testing verify mockito method-call

1
推荐指数
1
解决办法
7613
查看次数

Python实例方法进行多个实例方法调用

这是一些代码段.我已经测试了列出的方法并且它们正常工作,但是当我运行并测试此方法(countLOC)时,它似乎只是初始化具有实例方法call(i = self.countBlankLines())的第一个变量.有人知道我明显错过的明显原因吗?

def countLOC(self):  
    i = self.countBlankLines()  
    j = self.countDocStringLines()  
    k = self.countLines()  
    p = self.countCommentLines()  
    return k-i-j-p
Run Code Online (Sandbox Code Playgroud)

返回-3因为countBlankLines()返回3(正确).但是,它应该返回37 as countDocStringLines()= 6和countCommentLines()= 4而countLines()= 50.感谢.

python methods method-call

0
推荐指数
1
解决办法
221
查看次数

调用方法的最快方法

阅读本文后,我发现了几种调用方法的方法.

致电方法:

public static void SendData(string value) { }
Run Code Online (Sandbox Code Playgroud)

呼叫:

delegate void MyDelegate(string value);

//Slow method - NOT RECOMMENDED IN PRODUCTION!        
SendData("Update");

// Fast method - STRONGLY RECOMMENDED FOR PRODUCTION!
MyDelegate d = new MyDelegate(SendData);
d.BeginInvoke("Update", null, null);
Run Code Online (Sandbox Code Playgroud)

这是真的吗?它更快吗?

Action send = () => Send("Update");
send();
Run Code Online (Sandbox Code Playgroud)

或许这个?

我需要将一个方法调用到具有最高性能的SQL CLR触发器中,因此即使很小的速度增加也是有意义的.

.net c# lambda delegates method-call

0
推荐指数
2
解决办法
2337
查看次数

'newacc'不是类或名称空间

嘿伙计们,我对OOP和c ++都很新,所以请耐心等待.

我正在尝试定义一个类,它的功能,然后使用它们.我会展示到目前为止我所遇到的以及我遇到错误的地方.

在名为"account.h"的文件中,我有:

#include <iostream>
#include <string>
using namespace std;

class Account{
string fname;
string lname;
string sinnum;
string accttype;
int numtrans;
double balance;

public:
Account(string,string,string,string);
double DepositAmt(double);
double WithdrawAmt(double);
void PrintStatement();
void getFinalBalance();
};
Run Code Online (Sandbox Code Playgroud)

在一个名为"account.cpp"的文件中,我有:

Account::Account(string firstname, string lastname, string sinnumber, string acc
{
fname = firstname;
lname = lastname;
sinnum = sinnumber;
accttype = accounttype;
numtrans = 0;
balance = 0;
}

double Account::DepositAmt(double deposit)
{
balance = balance + deposit;
return balance;
}

double Account::WithdrawAmt(double withdraw) …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors method-call

0
推荐指数
1
解决办法
61
查看次数

检测文件是否存在

那么文件"MyStore.obj"和我下载的表一起附上了.我应该阅读这个文件的内容,这是与内容的顺序给出的.我可以确定它是否存在?因为你可以看到我尝试使用方法exists()但它没有用

import java.io.*;

public class sheet{
public static void main(String[]args){
try{
FileInputStream fis=new FileInputStream("MyStore.obj");

if(("MyStore.obj").exists()==false) //what can i do to fix this?

throw new FileNotFoundException("file doesn't exist");

ObjectInputStream ois=new ObjectInputStream(fis);

int numOfStorageDevice=ois.readInt();
int numOfComputerGames=ois.readInt();

StorageDevice [] sd=new StorageDevice[numOfStorageDevice];

for(int n=0;n<numOfStorageDevice;n++)
 sd[n]=(StorageDevice)ois.readObject();

 ComputerGame []cg=new ComputerGame[numOfComputerGames];

 for(int m=0;m<numOfComputerGames;m++)

 cg[m]=(ComputerGame)ois.readObject();

   File file=new File("Result.txt");
    FileOutputStream fos=new FileOutputStream(file);
   PrintWriter pr=new PrintWriter(fos);

 for(int i=0;i<numOfStorageDevice;i++){

 String model= sd[i].getmodel(); 
  /*and in the methodcall sd[i].getmodel() it keeps telling that
    the symbol cannot be found but i'm sure that the …
Run Code Online (Sandbox Code Playgroud)

java file method-call java-io

0
推荐指数
1
解决办法
2615
查看次数

调用参数化方法

在学习Java Generics参数化时,我想到了这段代码:

public interface Comparable<T> {
    public int compareTo(T o);
}

public static <T extends Comparable<T>> int countGreaterThan(T[] anArray, T elem) {
    int count = 0;
    for (T e : anArray)
        if (e.compareTo(elem) > 0)
            ++count;
    return count;
}
Run Code Online (Sandbox Code Playgroud)

我想测试它,所以我写了这个:

Integer[] iArray = new Integer[10];
for (int i=0; i<10; i++){
    iArray[i] = new Integer(i);
}

int a = countGreaterThan(iArray, Integer.valueOf(5));
Run Code Online (Sandbox Code Playgroud)

但是在调用方法时,编译器在最后一行给出了错误消息countGreaterThan:

The method countGreaterThan(T[], T) in the type Main is not applicable for the arguments (Integer[], Integer)
Run Code Online (Sandbox Code Playgroud)

我错过了一些明显的东西吗

java method-call

0
推荐指数
1
解决办法
50
查看次数

按照课程 - 我刚刚在函数中看到了一个奇怪的参数用法

我正在观看 C# 课程,我刚刚在参数中看到了 bool 的奇怪用法。

我将展示它的屏幕截图:

在此处输入图片说明

这意味着什么?我以前从未见过这样的事情。

c# parameters arguments method-signature method-call

0
推荐指数
1
解决办法
63
查看次数

方法链如何工作?

如何在下面的例子中getRequestDispatcher("xxx")调用getServletContext()?这样的调用程序如何工作?请给我一个关于这个背景的清晰图片.

RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp");
dispatcher.include(request, response);
Run Code Online (Sandbox Code Playgroud)

java jsp servlets calling-convention method-call

-1
推荐指数
1
解决办法
612
查看次数

在java swing中的action侦听器方法内部不调用方法

我必须在java swing actionperformed方法中调用一个方法.但是当我点击按钮时没有任何反应.如何解决这个问题呢?

       private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) 
   {
    hellocalled();
    }
    }
Run Code Online (Sandbox Code Playgroud)

java swing actionlistener method-call

-2
推荐指数
1
解决办法
1348
查看次数