• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

need a logic to test a boolean method that accept another class object as parameter

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't think of a logic to test the following code in a correct way.

I read that in java8 interface can implement boolean but it will error if we pass object class into it. That is if we try to overwrite object class through interface we'll get an error. Before trying it out I thought I'd first try to write something that makes uses of boolean method and accept objects into but I'm not sure what to write it without any idea.  Can someone think of something like bike, car or vehicle logic to write the below code to make more sense and so I can test various different methods of it. Maybe no need to write the code but give me a logic that I can implement?




Here is something I tried out for Interface.. I want a logic like this for the above code.



 
Bartender
Posts: 387
47
Firefox Browser MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there! I'm struggling a little to understand what you mean by

java8 interface can implement boolean

Are you speaking about boolean methods?
 
John Herrington
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, yea interface can implement boolean.

What I meant is that I don't know a case (like a real world scenario but very simple)  to use boolean class and method. This is just so I can practice a lot with different methods and scenarios. I only just learnt about boolean so I can't think of a case myself and Java is my first programming language.
Btw I've already completed the complete core java but going through tutorials second time and want to try various use case of each stuff.  I've been getting some ideas from youtube when I search for "java boolean example or tutorial" but haven't found a case where they pass object to boolean method.

 
John Herrington
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can think of writing a if statement for status and print something if its returns true which it does, but what's the point of passing "testing_2". Can't think of anything at the moment to  try out different ways to test.




Under PSVM



 
Marshal
Posts: 76867
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which book are you using? Is it Horstmann? That isn't a tutorial, nor a beginner's book. Also beware of things you find on YouTube; you don't know whether they are all right, or bad.
Please find out about the conventions for Java® identifiers. Don't use underscores. Don't call a class Interface1; that is a good recipe for confusing yourself later on. In your first example, yes, what is the point in that method taking a parameter at all? It doesn't use it.
Only write, “class object,” if you are making an instance of the Class class. Nor, “object class.”

I think you want to find out about the Predicate interface. Find a book like Modern Java in Action by Urma Fusco and Mycroft (Manning 2018) (or its older edition called Java8 in Action), and go through it looking for examples of use of the Predicate interface.
 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are speaking of Predicates -- as Campbell is guessing -- and you want to know of a real-life use for them, I use them for validation in a class I call Inputer.  This class prompts for a value at the command line.  You pass in the prompt and any validation you need with a predicate.
The i -> i > 0 is the predicate.
 
Campbell Ritchie
Marshal
Posts: 76867
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:. . . The i -> i > 0 is the predicate.

Maybe a bit more explanation of that λ would help. Try the Java™ Tutorials.
 
Crusading Chameleon likes the size of this ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic