Actually, Jan's way is probably the best... as if you wrongfully type
convert the wrong type, it'll panic (you'll need to know for sure that arr
in this instance will always be a boolean). With Jan's way, you're just
making a comparison of value... which will work regardless of the type.
On Mo
This... or just specify the type after 'arr' such as:
if arr.(bool) {
fmt.Println("This is a boolean value")
}
On Monday, January 29, 2018 at 5:41:17 AM UTC-6, Jan Mercl wrote:
>
> On Mon, Jan 29, 2018 at 12:36 PM pradam > wrote:
>
> > //here its throwing error like: non-boolean condition i
On Mon, Jan 29, 2018 at 12:36 PM pradam
wrote:
> //here its throwing error like: non-boolean condition in if statement
The compiler is right. 'arr' is not a boolean expresion, its type is
'interface{}'. Try: https://play.golang.org/p/zwNV9RD2oCs.
--
-j
--
You received this message because y
package main
import (
"fmt"
"reflect"
)
func main() {
array := []interface{}{true,1,"dodda"}
arr:=array[0]
fmt.Println(arr, reflect.TypeOf(arr)) // prints *true bool*
if arr{
fmt.Println("This is a boolean value") //here its throwing error
like: *non-boolean
condition in if statement*
}
}